class TableUI extends eui.Component {
    constructor() {
        super();
        this.skinName = "TableUISkin";
    }


    /** 球洞半径  默认值 28 */
    private holeR: number = 28;


    /**是否调试练习模式   练习按钮是否显示*/
    private DebugSingelModle: boolean = false;



    private ballX: number = 0;
    private ballY: number = 0;
    //调整边界
    private moveX: number = 0;
    private moveY: number = 0;
    /**球洞圆心之间的距离横向长度 */
    private holdDist_X: number = 480;
    /**球洞圆心之间的距离纵向长度 */
    private holdDist_Y: number = 496;
    //边长横向
    private edge_X: number = 428;
    //边长纵向
    private edge_Y: number = 446
    //中洞y坐标上的偏移
    //左右梯形底边距离d
    private middleDeviation: number = 21;
    //左右梯形底边距离
    private edge_LongX: number = 994;//上下梯形底边距离
    private edge_LongY: number = 525;
    //holdDist_X:number,holdDist_Y:number,hold_R:number,edge_X:number,edge_Y:number,middleDeviation:number,edge_LongX:number,edge_LongY:number
    //桌子梯形的变量
    private trapezoid_H: number = 21;
    private trapezoid_Long: number = 24;
    private trapezoid_Middle: number = 6;

    //TableUISkin.exml 中的内容
    private tableBG: eui.Image;
    private show: eui.Image;
    //表情 面板
    private biaoqing: eui.Panel;
    //玩家1玩家2 表情显示
    private p1b: eui.Image;
    private p2b: eui.Image;

    // private ButtonGroup: eui.Group;//facebook三控件
    // private tim: eui.Group;//时间组
    // private timetext: eui.Label;//时间预留
    // private sco: eui.Group;//分数组
    // private scoretext: eui.Label;//分数预留
    // private mul: eui.Group;//倍数组
    // private multiptext: eui.Label;//倍数预留

    // private Tips: eui.Image;//玩法预留
    private Aimer: eui.Image;//瞄准器预留
    // private back: eui.Image;//返回开始界面预留

    // private g: eui.Group;//连进
    // private goal: eui.Image;//连进1球
    // private goal0: eui.Image;//连进2球
    // private goal1: eui.Image;//连进3球
    private lidudi: eui.Image;//底板
    private liduLabel: eui.Label;//显示力量值
    private StrengthArm: eui.Image;//击球力度球杆
    private energy: eui.Image;//力量条

    // private timeGroup: eui.Group;//时间组
    // private seconds: eui.Image;//底板
    private leftNumImg: eui.Image;//时间左边的数字
    private rightNumImg: eui.Image;//时间右边的数字

    //小号球
    private smallGroup: eui.Group;
    private ball1: eui.Image;
    private ball2: eui.Image;
    private ball3: eui.Image;
    private ball4: eui.Image;
    private ball5: eui.Image;
    private ball6: eui.Image;
    private ball7: eui.Image;
    private ball8: eui.Image;
    private leftTurn: eui.Image;
    //大号球
    private bigGroup: eui.Group;
    private ball9: eui.Image;
    private ball10: eui.Image;
    private ball11: eui.Image;
    private ball12: eui.Image;
    private ball13: eui.Image;
    private ball14: eui.Image;
    private ball15: eui.Image;
    private ball16: eui.Image;
    private rightTurn: eui.Image;
    //所有球
    private ballImgArr: eui.Image[] = [];

    private stageX: number;
    private stageY: number;
    private whiteBall: eui.Image = null;//摆放白球标志
    private xIcon: eui.Image = null;//禁止标志
    private lianxiImg: eui.Image;//练习按钮
    private ganImg: eui.Image;//球杆


    public ballArr: NewBall[] = [];//所有3D画布上的球 白球0 实心1~7 花色9~15 黑八8 共16颗
    private bounce: number = -0.7;
    private tableX: number = 0;//桌子x
    private tableY: number = 0;//桌子y
    private tableW: number = 0;//桌长
    private tableH: number = 0;//桌宽
    public curBall: NewBall = null;//白球
    // public blackBall: NewBall = null;//黑球
    private ganLen: number = 581;//球杆图片长度（像素）
    private angleSpeed: number = 0;//球杆的角度
    private angleNum: number = 0;//球杆角度所在的象限
    private otherX: number = 0;//白球摆放起始点
    private otherY: number = 0;//白球摆放起始点
    private posArr: any[] = [];//球洞坐标信息







    private centerY: number = 0;//球桌中心y
    private centerX: number = 0;//球桌中心x


    private downStart: number = 744;
    private downOver: number = 820;
    private leftGroupPos: any;
    private rightGroupPos: any;
    private lianjiDragon: dragonBones.Armature;
    private ksDragon: dragonBones.Armature;
    private _r: number = 0;
    private removeBallArr: number[] = [];
    private firstCollision: number = 0;
    public isMove: boolean = false;
    private curVx: number = 0;
    private curVy: number = 0;
    //瞄准线
    private shp1: egret.Shape;  //白球第一段瞄准线
    private shp2: egret.Shape;  //白球 碰到的地方 画圆
    private shp2_2: egret.Shape;  //白球 碰到的第二个地方 画圆
    private shp3: egret.Shape;  //红线  被碰到的球的走向
    private shp4: egret.Shape;  //蓝线  白球走向
    private shp5: egret.Shape;  //白球碰壁 反射线
    public MyRange: eui.Image; //桌子可触摸范围


    private isBegin: boolean = false;//开始游戏？
    private huadongAngle: number = 0;
    private long: number = 0;
    private moveTime: number = 0;
    private tipsUI: TipsUI = new TipsUI();
    /**0不摆球，1摆球，2自由球 */
    public isBaiqiu: number = 0;
    public isOwnGame: boolean = false;//是否为游戏所有者
    private curActionNum: number = 0;
    private myChairId: number = -1;
    private otherChairId: number = -1;
    /**0 选择界面 1联机对战 2单机游戏 */
    private isLianxi: number = 0;
    public myBrowser: string = "";
    /**我的花色
     * -1=没有确定花色
     * 0=实心球（小）
     * 1=花心球（大）
     */
    public myColor: number = -1;
    private lightArr: dragonBones.Armature[] = [];
    private countdownTimer: egret.Timer;
    private curTimerNum: number = 0;
    /**0,空挡，1，是读条，2，是运行 */
    private isLoading: number = 0;
    private isKsBtn: boolean = false;
    private slip: eui.Image;
    private slipsize: number = 0;//改变的大小
    private startnum: number = 0;//记录第一次点击Y
    private istouchsp: boolean = false;//是否微调
    private startbg: eui.Image; //游戏开始背景
    private end: eui.Image;     //游戏结束背景
    private goplay: eui.Image;  //开始游戏按钮
    private close: eui.Image;   //结束界面关闭按钮
    private photo: eui.Image;   //玩家头像
    private playername: eui.Label;   //玩家名字
    private score: eui.Label;   //玩家得分文本
    private Maxscore: eui.Label;//玩家最高分文本
    private goaled: number = 100;    //玩家得分
    private maxgoal: number = 666; //玩家最高分
    private retry: eui.Image;  //重试
    private share: eui.Image;  //分享
    private offs: any[] = [];  //解散界面组件
    /**进球数*/
    public iii: number = 0; //回合进球数 ui连杆计算

    /**AI对战连杆 */
    public isAIComBoPK: boolean = false;
    /**真人对战连杆 */
    public isComBoPK: boolean = false;
    /**连杆确认花色进球 */
    public isComBoOK: boolean = false;
    /**累计得分 */
    private scoreiii: number = 0;
    private LIANxi: eui.Image;//无限火力**
    public ld: eui.Group;
    public slipgroup: eui.Group;//微调组
    private Combox: eui.Group;
    private p1: eui.Image;//women
    private p2: eui.Image;//men
    private photos: eui.Image[] = [];
    //声音变量
    // private soundganqiu: egret.Sound;
    // private soundrudong: egret.Sound;
    private soundzhuangbian: egret.Sound;
    // private soundzhuangqiu: egret.Sound;

    //测试区域
    private LastY: number;

    /**本地服务器 */
    public homeServer: FakeServerManage;
    /**打球先后顺序
     * 0-我方
     * 1-敌方
     */
    private order: number = 0;
    /**错误消息弹窗 */
    private errorMsgMain: ErrorMessage = new ErrorMessage();
    /**匹配计时器 */
    private matchTimer: egret.Timer = new egret.Timer(1000, 0);
    /**匹配超时数 */
    private matchTimeOutNum: number = GameData.matchWaitTime;
    /**等待匹配文字 */
    private matchMainLab: eui.Label;
    /**下回合操作状态
     * 0-空挡
     * 1-摆球
     * 2-自由球
     * 3-击球
     */
    private nextOperation: number;
    /**真人对战 true-我的回合 */
    public myLeg: boolean;
    /**本回合进球数 */
    private iiiNow: number = 0;
    /**本回合进的球 */
    private intoBallNow: any[] = [];
    /**本回合进球花色
     * 0-实心球（小号球）
     * 1-花球（大号球）
     */
    private ballColorNow: number = -1;
    /**本回合白球是否进洞 */
    private baiBallIntoNow: boolean = false;
    /**本回合黑球是否进洞 */
    private blackBallIntoNow: boolean = false;
    /**本回合是否为第一回合 */
    public isFirstLeg: boolean = false;
    /**玩家1名字 */
    private p1name: eui.Label;
    /**玩家2名字 */
    private p2name: eui.Label;
    /**击球颜色显示顺序 */
    public colorDisplayNum: number = 0;
    /**表情 */
    private note: eui.Image;
    /**击球判定显示 */
    public shootBallShow: eui.Label;
    /**联网模式对方杆的x位置 */
    public WEB_ganPointX: number = 0;
    /**联网模式对方杆的y位置 */
    public WEB_ganPointY: number = 0
    /**联网模式触摸X位置 */
    public WEB_stageX: number = 0;
    /**联网模式触摸Y位置 */
    public WEB_stageY: number = 0;
    /**断线重连显示 */
    public breakLineShow: eui.Label;
    /**球袋 */
    public golfBag: NewBall[] = [];
    /**球袋定时器 */
    public golfBagTimer: egret.Timer;
    /**球袋是否滚动 */
    public isGolfBagRoll: boolean = false;
    private stop: boolean = false;//时间暂停
    /**菜单 */
    private menu: eui.Group;
    /**继续游戏 */
    private goonGame: eui.Image;
    /**退出游戏 */
    private quitGame: eui.Image;
    protected createChildren(): void {
        super.createChildren();
        // this.serviceLine();
        //this.StartBg();
        //this.EndBg();
        this.Slip();
        this.touchImage();//点击透明图片定位置
        this.tableX = this.tableBG.x + this.moveX;
        this.tableY = this.tableBG.y + this.moveY;
        this.tableW = this.tableBG.width;
        this.tableH = this.tableBG.height;
        this.note.addEventListener(egret.TouchEvent.TOUCH_TAP, this.biaoqin, this)
        this.smallGroup.visible = false;
        this.bigGroup.visible = false;

        this.rightGroupPos = { x: this.smallGroup.x, y: this.smallGroup.y };
        this.leftGroupPos = { x: this.bigGroup.x, y: this.bigGroup.y };

        this.leftTurn.visible = false;
        this.rightTurn.visible = false;
        this.golfBag = [];
        // this.lin1 = RES.getRes("line_png");
        // var l = this.lin1;
        // this.lin2 = RES.getRes("line_png");
        // this.lin3 = RES.getRes("line_png");
        // this.lin4 = RES.getRes("line_png");
        // this.lin5 = RES.getRes("line_png");
        // this.addChild(l);
        // this.addChild(this.lin2);
        // this.addChild(this.lin3);
        // this.addChild(this.lin4);
        // this.addChild(this.lin5);


        this.posArr = [
            {
                x1: this.tableX + 184,
                y1: this.tableY + 146,
                x2: this.tableX + 144,
                y2: this.tableY + 180,
                hx: this.tableX + 160,
                hy: this.tableY + 155,
            },
            {
                x1: this.tableX + 613,
                y1: this.tableY + 146,
                x2: this.tableX + 666,
                y2: this.tableY + 146,
                hx: this.tableX + 640,
                hy: this.tableY + 130,
            },
            {
                x1: this.tableX + 1091,
                y1: this.tableY + 151,
                x2: this.tableX + 1129,
                y2: this.tableY + 185,
                hx: this.tableX + 1122,
                hy: this.tableY + 154,
            },
            {
                x1: this.tableX + 146,
                y1: this.tableY + 623,
                x2: this.tableX + 184,
                y2: this.tableY + 666,
                hx: this.tableX + 157,
                hy: this.tableY + 650,
            },
            {
                x1: this.tableX + 613,
                y1: this.tableY + 666,
                x2: this.tableX + 666,
                y2: this.tableY + 666,
                hx: this.tableX + 640,
                hy: this.tableY + 672,
            },
            {
                x1: this.tableX + 1129,
                y1: this.tableY + 616,
                x2: this.tableX + 1091,
                y2: this.tableY + 656,
                hx: this.tableX + 1122,
                hy: this.tableY + 648,

            }
        ];
        TableUI.Instance().ld.visible = false;
        TableUI.Instance().slipgroup.visible = false;
        this.photos = [this.p1, this.p2];
        this.centerX = this.posArr[0].hx + (this.posArr[2].hx - this.posArr[0].hx) * 0.5;
        this.centerY = this.posArr[0].hy + (this.posArr[3].hy - this.posArr[0].hy) / 2;
        //测试""
        var oomi = 0;
        // document.addEventListener("keydown", function (e: any) {
        //     // console.log("按下了", e.key);
        //     //     TableUI.Instance().addSmallBallLight();
        //     //     // TableUI._instance.addBigBallLight();
        //     // }
        //     if (e.keyCode == 13) {//回车
        //     }
        //     if (e.keyCode == 32) {//空格

        //         // TableUI.Instance().BallArrToShow();
        //     }
        // });



        //for(var i:number=0;i<this.posArr.length;i++)
        //{
        //    var shp:egret.Shape = new egret.Shape();
        //    shp.graphics.lineStyle( 1, 0x00ff00 );
        //    shp.graphics.drawCircle(this.posArr[i].x1,this.posArr[i].y1,1);
        //    shp.graphics.endFill();
        //    this.addChild(shp);
        //
        //    var shp1:egret.Shape = new egret.Shape();
        //    shp1.graphics.lineStyle( 1, 0x00ff00 );
        //    shp1.graphics.drawCircle(this.posArr[i].x2,this.posArr[i].y2,1);
        //    shp1.graphics.endFill();
        //    this.addChild(shp1);
        //
        //    var shp2:egret.Shape = new egret.Shape();
        //    shp2.graphics.lineStyle( 1, 0x00ff00 );
        //    shp2.graphics.drawCircle(this.posArr[i].hx,this.posArr[i].hy,this.holeR);
        //    shp2.graphics.endFill();
        //    this.addChild(shp2);
        //}
        this.ganImg = new eui.Image("gan");
        this.ganImg.anchorOffsetX = 12;
        this.ganImg.anchorOffsetY = 5;
        this.ganImg.visible = false;
        this.addChild(this.ganImg);

        this.lianxiImg = new eui.Image("lianxiBtn1");
        this.lianxiImg.anchorOffsetX = 48;
        this.lianxiImg.x = this.centerX;
        this.lianxiImg.y = this.centerY + 170;
        this.addChild(this.lianxiImg);
        this.lianxiImg.name = "lianxi";
        this.lianxiImg.visible = this.DebugSingelModle; //隐藏最初开始
        var dragonbonesData = RES.getRes("ks3");
        var textureData = RES.getRes("ks2");
        var texture = RES.getRes("ks1");
        var dragonbonesFactory: dragonBones.EgretFactory = new dragonBones.EgretFactory();
        dragonbonesFactory.addDragonBonesData(dragonBones.DataParser.parseDragonBonesData(dragonbonesData));
        dragonbonesFactory.addTextureAtlas(new dragonBones.EgretTextureAtlas(texture, textureData));
        this.ksDragon = dragonbonesFactory.buildArmature("armatureName");
        this.ksDragon.display.name = "ks";
        this.addChild(this.ksDragon.display);
        this.isKsPlay = true;
        this.ksDragon.display.x = this.centerX;
        this.ksDragon.display.y = this.centerY + 80;
        dragonBones.WorldClock.clock.add(this.ksDragon);

        this.ksDragon.addEventListener(egret.Event.COMPLETE, function () {
            //dragonBones.WorldClock.clock.remove(_this.ksDragon);
            this.isKsBtn = true;
            this.isKsPlay = false;
            this.ksDragon.display.touchEnabled = true;
            this.ksDragon.display.addEventListener(egret.TouchEvent.TOUCH_TAP, this.startConnect, this);

            this.lianxiImg.addEventListener(egret.TouchEvent.TOUCH_TAP, this.lianxiFunc, this);
        }.bind(this), this);
        this.ksDragon.animation.gotoAndPlay("zq_ks_01a", -1, -1, 1);


        // var dragonbonesData1 = RES.getRes("lianji3");
        // var textureData1 = RES.getRes("lianji2");
        // var texture1 = RES.getRes("lianji1");
        var dragonbonesData1 = RES.getRes("liangan3_json");
        var textureData1 = RES.getRes("liangan2_json");
        var texture1 = RES.getRes("liangan1_png");//资源名字
        var dragonbonesFactory1: dragonBones.EgretFactory = new dragonBones.EgretFactory();
        dragonbonesFactory1.addDragonBonesData(dragonBones.DataParser.parseDragonBonesData(dragonbonesData1));
        dragonbonesFactory1.addTextureAtlas(new dragonBones.EgretTextureAtlas(texture1, textureData1));
        this.lianjiDragon = dragonbonesFactory1.buildArmature("Armature");//龙骨名字
        this.lianjiDragon.display.x = this.centerX + 430;
        this.lianjiDragon.display.y = this.centerY;
        egret.Ticker.getInstance().register(
            function (frameTime: number) {
                dragonBones.WorldClock.clock.advanceTime(frameTime / 1000);
                return true;
            },
            this
        );
        // document.addEventListener("mousemove", this.mouseMoveGan);

        this.setTimeNum(0);

        this.myBrowser = getBrowserType();

        this.shp1 = new egret.Shape();
        this.shp2 = new egret.Shape();
        this.shp2_2 = new egret.Shape();
        this.shp3 = new egret.Shape();
        this.shp4 = new egret.Shape();
        this.shp5 = new egret.Shape();

        this.addChild(this.shp1);
        this.addChild(this.shp2);
        this.addChild(this.shp2_2);
        this.addChild(this.shp3);
        this.addChild(this.shp4);
        this.addChild(this.shp5);

        // this.shp1.alpha = 0.6;
        // this.shp2.alpha = 0.6;
        // this.shp3.alpha = 0.6;
        // this.shp4.alpha = 0.6;
        // this.shp5.alpha = 0.6;

        this.long = 0;
        this.UpdateLiduLabel();

        // this.promptWord = new PromptWord();
        // this.promptWord.anchorOffsetX = 138;
        // this.promptWord.x = this.centerX;
        // this.promptWord.y = this.centerY - 230;
        this.promptWord.touchEnabled = false;

        // this.soundganqiu = RES.getRes("ganqiu");
        // this.soundrudong = RES.getRes("rudong");
        this.soundzhuangbian = RES.getRes("zhuangbian_mp3");
        // this.soundzhuangqiu = RES.getRes("zhuangqiu");
        //修改球案数据
        // this.AdjustposArr(this.holdDist_X,this.holdDist_Y,this.holeR,this.edge_X,this.edge_Y,this.middleDeviation,this.edge_LongX,this.edge_LongY);
        //将球案边添加一个梯形
        this.TrapezoidBallSide(this.trapezoid_Long, this.trapezoid_Middle, this.trapezoid_H);

        //画球案
        // this.debugDrawTable();

        this.InitShowBall();//初始化进球显示

        this.addGanEvt();//初始化击球力度

        this.whitei();//初始化瞄准球

        this.initBackAndVoice();//初始化返回及语音按钮

        this.initSoundRES();

        this.initlinpic();//初始化瞄准线图片

        this.p1name.text = randomName.getInstance().getRandomName();
        this.p2name.text = randomName.getInstance().getRandomName();

        // egret.setTimeout(() => { this.setganimgAsFirstBliding() },
        //     this,
        //     1000 / 60)
        this.setGanOver(this.p1);

    }
    /**连杆测试用 */
    public xxx = 0;
    /**表情面板打开监听 */
    private biaoqin() {
        this.biaoqing.visible = true;
        this.biaoqing.alpha = 0;
        Tween.get(this.biaoqing).to({ alpha: 1 }, 300);
        this.biaoqing.enabled = true;
        this.biaoqing.getChildAt(5).addEventListener(egret.TouchEvent.TOUCH_TAP, this.biaoqingoff, this);

        this.biaoqing.getChildAt(1).addEventListener(egret.TouchEvent.TOUCH_TAP, () => {
            this.ShowMyFace(1);
            var tw = egret.Tween.get(this.biaoqing.getChildAt(1));
            tw.to({ scaleX: 1.2, scaleY: 1.2 }, 100);
            tw.to({ scaleX: 1, scaleY: 1 }, 100);
            if (webNetworkMananger.getInstance().isMoving) {
                try {
                    //发送表情
                    webNetworkMananger.getInstance().sendFace(1);
                } catch (e) {
                    console.log("Waring: " + e);
                }
            }
        }, this);
        this.biaoqing.getChildAt(2).addEventListener(egret.TouchEvent.TOUCH_TAP, () => {
            this.ShowMyFace(2);
            var tw = egret.Tween.get(this.biaoqing.getChildAt(2));
            tw.to({ scaleX: 1.2, scaleY: 1.2 }, 100);
            tw.to({ scaleX: 1, scaleY: 1 }, 100);
            if (webNetworkMananger.getInstance().isMoving) {
                try {
                    //发送表情
                    webNetworkMananger.getInstance().sendFace(2);
                } catch (e) {
                    console.log("Waring: " + e);
                }
            }
        }, this);
        this.biaoqing.getChildAt(3).addEventListener(egret.TouchEvent.TOUCH_TAP, () => {
            this.ShowMyFace(3);
            var tw = egret.Tween.get(this.biaoqing.getChildAt(3));
            tw.to({ scaleX: 1.2, scaleY: 1.2 }, 100);
            tw.to({ scaleX: 1, scaleY: 1 }, 100);
            if (webNetworkMananger.getInstance().isMoving) {
                try {
                    //发送表情
                    webNetworkMananger.getInstance().sendFace(3);
                } catch (e) {
                    console.log("Waring: " + e);
                }
            }
        }, this);
        this.biaoqing.getChildAt(4).addEventListener(egret.TouchEvent.TOUCH_TAP, () => {
            this.ShowMyFace(4);
            var tw = egret.Tween.get(this.biaoqing.getChildAt(4));
            tw.to({ scaleX: 1.2, scaleY: 1.2 }, 100);
            tw.to({ scaleX: 1, scaleY: 1 }, 100);
            if (webNetworkMananger.getInstance().isMoving) {
                try {
                    //发送表情
                    webNetworkMananger.getInstance().sendFace(4);
                } catch (e) {
                    console.log("Waring: " + e);
                }
            }
        }, this);
    }
    /**关闭表情面板 结束监听 */
    private biaoqingoff() {
        Tween.get(this.biaoqing).to({ alpha: 0 }, 300).call(() => {
            this.biaoqing.visible = false;
        });
        this.biaoqing.enabled = false;

        //Here is a problem
        // for (var q = 0; q < 4; q++) {
        //     this.biaoqing.getChildAt(q + 1).removeEventListener(egret.TouchEvent.TOUCH_TAP, () => {
        //                    if (webNetworkMananger.isServerMove) {
        //             webNetworkMananger.getInstance().sendFace(q);
        //             console.log("解除表情监听" + q);
        //         }
        //     }, this);
        // }


        this.biaoqing.getChildAt(1).removeEventListener(egret.TouchEvent.TOUCH_TAP, () => {
            this.ShowMyFace(1);
            if (webNetworkMananger.getInstance().isMoving) {
                try {
                    //发送表情
                    webNetworkMananger.getInstance().sendFace(1);
                } catch (e) {
                    console.log("Waring: " + e);
                }
            }
        }, this);
        this.biaoqing.getChildAt(2).removeEventListener(egret.TouchEvent.TOUCH_TAP, () => {
            this.ShowMyFace(2);
            if (webNetworkMananger.getInstance().isMoving) {
                try {
                    //发送表情
                    webNetworkMananger.getInstance().sendFace(2);
                } catch (e) {
                    console.log("Waring: " + e);
                }
            }
        }, this);
        this.biaoqing.getChildAt(3).removeEventListener(egret.TouchEvent.TOUCH_TAP, () => {
            this.ShowMyFace(3);
            if (webNetworkMananger.getInstance().isMoving) {
                try {
                    //发送表情
                    webNetworkMananger.getInstance().sendFace(3);
                } catch (e) {
                    console.log("Waring: " + e);
                }
            }
        }, this);
        this.biaoqing.getChildAt(4).removeEventListener(egret.TouchEvent.TOUCH_TAP, () => {
            this.ShowMyFace(4);
            if (webNetworkMananger.getInstance().isMoving) {
                try {
                    //发送表情
                    webNetworkMananger.getInstance().sendFace(4);
                } catch (e) {
                    console.log("Waring: " + e);
                }
            }
        }, this);
    }
    /**
     * 点击图片定位置
     */
    private touchImage() {
        this.MyRange.touchEnabled = true;
        this.MyRange.addEventListener(egret.TouchEvent.TOUCH_TAP, this.startMyRange, this);
        this.MyRange.addEventListener(egret.TouchEvent.TOUCH_MOVE, this.moveMyRange, this);
    }
    private startMyRange(evt: egret.TouchEvent) {
        if (this.isBaiqiu == 0) {
            if (this.isCanMove) {
                this.XX = evt.stageX;
                this.YY = evt.stageY;
                this.moveGan(evt.stageX, evt.stageY);

            }
        }
        if (this.white.visible) {
            this.white.visible = false;
            this.red.visible = false;
        }
    }
    private moveMyRange(evt: egret.TouchEvent) {

        if (this.isCanMove && (this.isBaiqiu == 0)) {
            this.XX = evt.stageX;
            this.YY = evt.stageY;
            //console.log("x:" + this.XX + "     y:" + this.YY);
            this.moveGan(evt.stageX, evt.stageY);
        }
    }
    private CSComx() {
        if (webNetworkMananger.getInstance().isMoving && this.isLianxi == 1) {
            // 联网确认自己花色连杆
            if (this.myColor == 0) {
                // if (b.idx < 8) {
                this.isComBoPK = true;
                this.isComBoOK = true;
                this.iii++;
                // }
            } else if (this.myColor == 1) {
                // if (b.idx > 8) {
                this.isComBoPK = true;
                this.isComBoOK = true;
                this.iii++;
                // }
            }
            else if (this.myColor = -1) {
                this.iii++;
                this.isComBoOK = true;
                this.isComBoPK = true;
            }
        }
        if (!webNetworkMananger.getInstance().isMoving && this.isLianxi == 1) {
            //AI 模式
            if (FakeServerManage.getInstance().getNowLegShootColor() == 0) {
                // if (b.idx < 8) {
                this.isComBoOK = true;
                this.isAIComBoPK = true;
                this.iii++;
                // }
            } else if (FakeServerManage.getInstance().getNowLegShootColor() == 1) {
                // if (b.idx > 8) {
                this.isComBoOK = true;
                this.isAIComBoPK = true;
                this.iii++;
                // }
            }
            else if (FakeServerManage.getInstance().getNowLegShootColor() == -1) {
                this.iii++;
                this.isComBoOK = true;
                this.isAIComBoPK = true;
            }
        }
        if (this.isFirstLeg) {
            this.iii = 0;
        }

        if (webNetworkMananger.getInstance().isMoving && this.isLianxi == 1) {
            if (TableUI.Instance().isComBoPK) {//联网 连杆特效
                if (TableUI.Instance().isComBoOK) {
                    console.log(TableUI.Instance().iii, "真人连杆iiiiiii")
                    this.numii += TableUI.Instance().iii;
                    console.log(this.numii, "真人连杆杆杆")
                    // TableUI.Instance().ShowComBo(ball.isJindong, this.numii);
                    this.iii = 0;
                    this.isComBoOK = false;
                }
            } else {
                this.numii = 0;
            }
        }
        if (!webNetworkMananger.getInstance().isMoving && this.isLianxi == 1) {
            if (this.isAIComBoPK) {
                if (this.isComBoOK) {
                    console.log(TableUI.Instance().iii, "AI连杆iiiiiii")
                    this.numii += TableUI.Instance().iii;
                    console.log(this.numii, "AI连杆杆杆")
                    // TableUI.Instance().ShowComBo(ball.isJindong, this.numii);
                    this.iii = 0;
                    this.isComBoOK = false;
                }
            } else {
                this.numii = 0;
            }
        }
    }
    /**
    * 白瞄准
    */
    private white: eui.Image;
    private red: eui.Image;
    private whitei() {
        this.white = new eui.Image("white");
        this.white.x = 393;
        this.white.y = 158;
        this.addChild(this.white);
        this.red = new eui.Image("red");
        this.red.x = 623;
        this.red.y = 383;
        this.addChild(this.red);

        this.red.visible = false;
        this.white.visible = false;
        this.Aimer.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.startwhitei, this);
        this.white.addEventListener(egret.TouchEvent.TOUCH_MOVE, this.movewhitei, this);
        this.red.touchEnabled = false;
        //   1225.74    607.38
        this.mx = this.ballpoint.x;
        this.my = this.ballpoint.y;
        this.white.touchEnabled = true;
    }

    private startwhitei(evt: egret.TouchEvent) {


        if (this.white.visible) {
            this.white.visible = false;
            this.red.visible = false;
            this.MyRange.touchEnabled = true;
            if (this.ismeturn()) {
                this.LighttoMyBalls();
                this.ShowGanImg();
            }
        } else {
            this.white.visible = true;
            this.red.visible = true;
            this.ClearAllLine();
            this.HideGanImg();
        }

        var m: number = this.getChildIndex(this.MyRange);
        if (this.whiteBall == null) {
            this.setChildIndex(this.white, m + 10);
            this.setChildIndex(this.red, m + 11);
        } else {
            var b: number = this.getChildIndex(this.whiteBall);
            var x: number = this.getChildIndex(this.xIcon);
            this.setChildIndex(this.white, b + 1);
            this.setChildIndex(this.red, b + 2);
            if (this.xIcon != null) {
                this.setChildIndex(this.white, x + 1);
                this.setChildIndex(this.red, x + 2);
            }

        }
    }
    private ballpoint: eui.Image;
    //初始偏移
    private mx: number;
    private my: number;

    private movewhitei(evt: egret.TouchEvent) {

        var sx = (evt.stageX - 630);
        var sy = (evt.stageY - 400); var dist = Math.sqrt(sx * sx + sy * sy);
        if (dist < 220) {
            this.red.x = evt.stageX - this.red.width / 2;
            this.red.y = evt.stageY - this.red.height / 2;


            this.ballpoint.x = this.red.x * 0.08 + this.mx - 50;
            this.ballpoint.y = this.red.y * 0.1 + this.my - 35;
        }
    }

    /**发球线 */
    private serviceLine() {
        var shp: egret.Shape = new egret.Shape();
        shp.graphics.lineStyle(1.5, 0x0000FF);
        shp.graphics.moveTo(400, 165);
        shp.graphics.lineTo(400, 635);
        shp.graphics.lineTo(800, 720);
        shp.graphics.lineTo(1200, 550);
        shp.graphics.lineTo(400, 165);
        shp.graphics.endFill();
        this.addChild(shp);
    }
    /**
     * 微调
     */
    private Slip() {
        // var long = 751 * 0.7
        // var rect: egret.Rectangle = new egret.Rectangle(12, 0, 68, 412);
        var shape: egret.Shape = new egret.Shape();
        shape.graphics.beginFill(0x00ff00);
        shape.graphics.drawRoundRect(40, -7, 70, 400, 100, 100);
        shape.graphics.endFill();
        shape.alpha = 0;
        this.slipgroup.addChild(shape);
        shape.touchEnabled = false;
        this.slip.mask = shape;
        this.slip.touchEnabled = true;
        this.slip.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.startime, this);
        this.slip.addEventListener(egret.TouchEvent.TOUCH_MOVE, this.onTouch, this);
        this.slip.addEventListener(egret.TouchEvent.TOUCH_END, this.notouchsp, this);
    }
    private notouchsp(evt: egret.TouchEvent) {//结束微调
        this.istouchsp = false;
    }
    private XX: number = 0;
    private YY: number = 0;
    private startime(evt: egret.TouchEvent) {
        this.startnum = evt.stageY;
    }
    private onTouch(evt: egret.TouchEvent) {
        this.istouchsp = true;
        if (evt.stageY > this.startnum) {//下滑
            this.slip.y += 1.5;
            //this.slip.mask.y -= 1.5;
            this.slipsize += 0.15;     //杆下移
        } else if (evt.stageY < this.startnum) {//上滑
            this.slip.y -= 1.5;
            // this.slip.mask.y += 1.5;
            this.slipsize -= 0.15;     //杆上移
        }
        //记录本次 evt.stageY 值赋给startnum 下次判断使用
        this.startnum = evt.stageY
        // console.log(this.slip.y);
        if (this.slip.y >= -25) {
            this.slip.y -= 60;
            //this.slip.mask.y += 199;
        }
        else if (this.slip.y <= -85) {
            this.slip.y += 60;
            //this.slip.mask.y -= 156;
        }
        //当实现功能前把鼠标X，Y定死只改变差值（定值XX，YY）
        if (TableUI.Instance().isCanMove) {
            if (TableUI.Instance().istouchsp && !TableUI.Instance().isMove) {
                TableUI.Instance().moveGan(this.XX, this.YY);
            }
        }
        //egret.setTimeout(() => { },this, 100);
        //console.log(this.slip.mask.y);//改变的大小
    }
    /**
  * 游戏开始界面
  */
    private StartBg() {
        this.startbg = new eui.Image("start");
        this.startbg.width = this.stage.stageWidth / 3;  //480
        this.startbg.height = this.stage.stageHeight;    //900
        this.startbg.x = this.stage.stageWidth / 2 - this.startbg.width / 2;
        this.addChild(this.startbg);
        this.goplay = new eui.Image("kaishi");
        this.goplay.width = this.stage.stageWidth / 9;
        this.goplay.height = this.stage.stageHeight / 8;
        this.goplay.x = 750;
        this.goplay.y = 750;
        this.addChild(this.goplay);
        this.goplay.visible = false;//暂未用
        this.goplay.addEventListener(egret.TouchEvent.TOUCH_TAP, this.lianxiFunc, this);//开始练习
        this.goplay.addEventListener(egret.TouchEvent.TOUCH_TAP, this.HidstartBg, this);
    }
    /**
     * 隐藏开始界面
     */
    private HidstartBg() {
        this.startbg.visible = false;
        //this.goplay.visible = false;

    }
    /**
    * 游戏结束界面
    */
    private EndBg() {
        this.end = new eui.Image("lose");
        this.end.width = this.stage.stageWidth / 2.5;
        this.end.height = this.stage.stageHeight;
        this.end.x = this.stage.stageWidth / 2 - this.end.width / 2;
        this.addChild(this.end);
        this.close = new eui.Image("off");
        this.close.x = 890;
        this.addChild(this.close);
        this.close.addEventListener(egret.TouchEvent.TOUCH_TAP, this.HidEndBg, this); //关闭按钮 触发的事件
        this.close.addEventListener(egret.TouchEvent.TOUCH_TAP, this.lianxiFunc, this);//重新练习
        this.photo = new eui.Image("player");
        this.photo.width = this.stage.stageWidth / 8;
        this.photo.height = this.stage.stageHeight / 8;
        this.photo.x = this.stage.stageWidth / 2 - this.photo.width / 2 - 80;
        this.photo.y = 50;
        this.addChild(this.photo);
        this.playername = new eui.Label();
        this.playername.text = "Mary";
        this.playername.x = this.stage.stageWidth / 2 - this.photo.width / 2 + 150;
        this.playername.y = 130;
        this.playername.bold = true;
        this.addChild(this.playername);
        var scoretxt: eui.Label;
        scoretxt = new eui.Label();
        scoretxt.text = "得分";
        scoretxt.x = this.stage.stageWidth / 2 - this.photo.width / 2
        scoretxt.y = 230;
        scoretxt.textColor = 0xD9D919;
        scoretxt.bold = true;
        this.addChild(scoretxt);
        this.score = new eui.Label();   //玩家得分
        // this.score.text = "" + this.goal;
        this.score.x = this.stage.stageWidth / 2 - this.photo.width / 2
        this.score.y = 310;
        this.score.size = 90;
        this.score.bold = true;
        this.addChild(this.score);
        var Maxscoretxt: eui.Label;
        Maxscoretxt = new eui.Label();
        Maxscoretxt.text = "高分";
        Maxscoretxt.x = this.stage.stageWidth / 2 - this.photo.width / 2
        Maxscoretxt.y = 430;
        Maxscoretxt.textColor = 0xD9D919;
        Maxscoretxt.bold = true;
        this.addChild(Maxscoretxt);
        this.Maxscore = new eui.Label();//玩家最高分
        this.Maxscore.text = "" + this.maxgoal;
        this.Maxscore.size = 75;
        this.Maxscore.x = this.stage.stageWidth / 2 - this.photo.width / 2
        this.Maxscore.y = 510;
        this.Maxscore.bold = true;
        this.addChild(this.Maxscore);
        var ComeOn: eui.Label;
        ComeOn = new eui.Label();
        ComeOn.text = "每个绅士都会打撞球,不过打太好的不算";
        ComeOn.x = this.stage.stageWidth / 2 - 210;
        ComeOn.y = 630;
        ComeOn.size = 25;
        ComeOn.textColor = 0xA68064;
        this.addChild(ComeOn);
        this.retry = new eui.Image("retry");
        this.retry.x = this.stage.stageWidth / 2 - 200;
        this.retry.y = 730;
        this.addChild(this.retry);
        this.retry.addEventListener(egret.TouchEvent.TOUCH_TAP, this.HidEndBg, this);  //重开一局 触发的事件
        this.retry.addEventListener(egret.TouchEvent.TOUCH_TAP, this.lianxiFunc, this);//重新练习
        this.share = new eui.Image("share");//分享
        this.share.x = this.stage.stageWidth / 2 + 20;
        this.share.y = 730;
        this.addChild(this.share);
        this.share.addEventListener(egret.TouchEvent.TOUCH_TAP, this.Share, this);  //分享游戏 触发的事件
        this.offs = [this.end, this.close, this.photo, this.playername, scoretxt, this.score, Maxscoretxt, this.Maxscore, ComeOn, this.retry, this.share];
    }
    /**
     * 重新开始 隐藏结算界面
     */
    private HidEndBg() {
        for (var i: number = 0; i < this.offs.length; i++) {
            this.offs[i].visible = false;
        }
    }
    /**
     * 分享游戏
     */
    private Share() {

    }
    /**
     播放连击特效  
     m 洞口，n:连击数（2~8）
    */
    public ShowComBo(m: number, n: number): void {
        var hole = this.Combox.$children;
        this.lianjiDragon.display.x = hole[m].x;
        this.lianjiDragon.display.y = hole[m].y;

        if (n < 2) return;
        if (n > 7) n = 7;
        if (!this.lianjiDragon.display.parent) {
            this.addChild(this.lianjiDragon.display);
        }
        dragonBones.WorldClock.clock.add(this.lianjiDragon);
        this.lianjiDragon.addEventListener(egret.Event.COMPLETE, function () {
            dragonBones.WorldClock.clock.remove(this.lianjiDragon);
            if (this.lianjiDragon.display.parent) {
                this.removeChild(this.lianjiDragon.display);
            }

        }.bind(this), this);
        // this.lianjiDragon.animation.gotoAndPlay("zq_00" + n + "a", -1, -1, 1);//动画名字
        this.lianjiDragon.animation.play("combox_" + n, 1);//动画名字
        this.PlaySoundWithVolume(1, this.comboSound);
        return;
    }
    private touxiang: dragonBones.Armature;
    /**联网确定花色 */
    public SMColor(msg) {
        var num: number = msg;
        for (var t = 0; t < this.ballImgArr.length; t++) {//重置位置
            this.ballImgArr[t].y = this.bigGroup.y - 23;
            // if (t < 8) {
            //     this.ballImgArr[t].x = 0 + t * 40;
            // } else {
            //     this.ballImgArr[t].x = 0 + (14 - t) * 40;
            // }
        }

        this.smallGroup.visible = true;
        this.bigGroup.visible = true;

        if (num == 0) {//我是全色
            this.smallGroup.x = this.leftGroupPos.x;
            this.smallGroup.y = this.leftGroupPos.y;


            this.bigGroup.x = this.rightGroupPos.x;
            this.bigGroup.y = this.rightGroupPos.y;
            for (var t = 0; t < this.ballImgArr.length; t++) {//位置
                if (t < 8) {
                    this.ballImgArr[t].x = 0 + (7 - t) * 40;//全色逆序
                } else {
                    this.ballImgArr[t].x = 0 + (t - 8) * 40;//花色正序
                }
            }
        }
        if (num == 1) {//我是花色
            this.smallGroup.x = this.rightGroupPos.x;
            this.smallGroup.y = this.rightGroupPos.y;

            this.bigGroup.x = this.leftGroupPos.x;
            this.bigGroup.y = this.leftGroupPos.y;
            for (var t = 0; t < this.ballImgArr.length; t++) {//位置
                if (t < 8) {
                    this.ballImgArr[t].x = 0 + t * 40;//全色正序
                } else {
                    this.ballImgArr[t].x = 0 + (14 - t) * 40 + 40;//花色逆序
                }
            }
        }
        this.ball8.x = this.ball1.x;
        this.ball16.x = this.ball9.x;
    }

    private lianxiFunc() {
        //this.startbg.visible = false; // 隐藏开始界面
        var _spr2: egret.DisplayObject = this.getChildByName("ks");
        _spr2.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.startConnect, this);
        if (_spr2.parent) {
            this.removeChild(_spr2);
        }
        this.isKsBtn = false;

        var _spr3: egret.DisplayObject = this.getChildByName("lianxi");
        _spr3.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.lianxiFunc, this);
        if (_spr3.parent) {
            this.removeChild(_spr3);
        }

        this.isLianxi = 2;

        this.isOwnGame = true;

        this.isBaiqiu = 1;

        this.bigGroup.visible = true;
        this.smallGroup.visible = true;

        this.setSour('Waiting for Game Start...');
        // var dengdai: eui.Label = new eui.Label();
        // dengdai.text = "等待游戏开始...";
        // dengdai.width = 1440;
        // dengdai.y = this.centerY;
        // dengdai.name = "dengdai";
        // dengdai.textAlign = egret.HorizontalAlign.CENTER;
        // this.addChild(dengdai);

        egret.setTimeout(this.startGame1, this, 100);
    }
    /**联网模式 */
    private startConnect() {
        this.isLianxi = 1;
        var _spr2: egret.DisplayObject = this.getChildByName("ks");
        _spr2.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.startConnect, this);
        if (_spr2.parent) {
            this.removeChild(_spr2);
        }
        this.isKsBtn = false;
        this.isKsPlay = false;
        dragonBones.WorldClock.clock.remove(this.ksDragon);

        var _spr3: egret.DisplayObject = this.getChildByName("lianxi");
        _spr3.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.lianxiFunc, this);
        if (_spr3.parent) {
            this.removeChild(_spr3);
        }
        this.setSour('Waiting for Game Start...');
        // var dengdai: eui.Label = new eui.Label();
        // dengdai.text = "等待其他玩家...";
        // dengdai.width = 1440;
        // dengdai.y = this.centerY;
        // dengdai.name = "dengdai";
        // dengdai.textAlign = egret.HorizontalAlign.CENTER;
        // this.addChild(dengdai);
        // this.matchMainLab = dengdai;

        egret.setTimeout(e => {
            if (GameData.isStandalone) {
                this.homeServer = FakeServerManage.getInstance();
                this.startGame1();
            } else {
                webNetworkMananger.getInstance().gameSceneRec = this;
                webNetworkMananger.getInstance().connect();
            }
        }, this, 1000 / 60);

    }
    /**等待匹配 */
    public waitingMatch() {
        this.matchTimer = new egret.Timer(1000, GameData.matchWaitTime);
        this.matchTimer.addEventListener(egret.TimerEvent.TIMER, this.waitMsgShow, this);
        this.matchTimer.addEventListener(egret.TimerEvent.TIMER_COMPLETE, this.matchTimeout, this);
        this.matchTimer.start();
    }
    /**等待信息显示 */
    public waitMsgShow() {
        this.matchTimeOutNum--;
        this.setSour("Waiting for opponent..." + this.matchTimeOutNum + "s");
    }
    /**匹配超时处理 */
    public matchTimeout() {
        this.matchTimer.stop();
        this.matchTimer.removeEventListener(egret.TimerEvent.TIMER, this.waitMsgShow, this);
        this.matchTimer.removeEventListener(egret.TimerEvent.TIMER, this.waitMsgShow, this);
        this.matchTimeOutNum = GameData.matchWaitTime;
        this.setSour('Match overtime');
    }
    /**匹配成功 */
    public matchSuccessful() {
        this.matchTimeout();
        this.startGame1();
    }
    public isCanClose: boolean = false;
    /**联网登录 */
    private SMLogin(msg) {
        GameData.myAccount = msg.playerState.account;
    }
    /**显示玩家数据 */
    public SMShowPlayerData() {
        this.p1name.text = GameData.myUserData.name;
        this.p2name.text = GameData.rivalUserData.name;
    }
    /**摆球、自由球 */
    public SMPutBall(msg) {
        this.isBaiqiu = msg.type;
        this.isBaiqiu = 0;
        this.curBall.isJindong = -1;
        this.curBall.lastX = this.curBall.nextX = Number(msg.x);
        this.curBall.lastY = this.curBall.nextY = Number(msg.y);
        setBaiPos(msg.x, msg.y);
        refreshUI();
    }

    private idTO1: number;
    /**联网游戏结束 */
    private SMGameEnd(msg) {
        if (this.isLosePrompt) {
            this.idTO1 = egret.setTimeout(this.SMGameEnd1, this, 3000, msg);
        } else {
            this.SMGameEnd1(msg);
        }
    }
    private SMGameEnd1(msg) {
        if (this.isLosePrompt) {
            egret.clearTimeout(this.idTO1);
            this.isLosePrompt = false;
        }
        this.countdownFunc(false);
        if (msg.code == 1) {
            return;
        }
        this.isOwnGame = false;
        this.isBaiqiu = 0;
        this.ganImg.visible = false;
        this.shp1.graphics.clear();
        this.shp2.graphics.clear();
        this.shp2_2.graphics.clear();
        this.shp3.graphics.clear();
        if (msg.winChair == this.myChairId) {
            var winUI: WinUI = new WinUI();
            winUI.x = this.centerX - 546 / 2;
            winUI.y = this.centerY - 469 / 2;

            this.addChild(winUI);
            winUI.playAction();
        }
        else {
            var loseUI: LoseUI = new LoseUI();
            loseUI.x = this.centerX - 546 / 2;
            loseUI.y = this.centerY - 469 / 2;

            this.addChild(loseUI);
            loseUI.playAction();
        }

    }
    /**联网杆移动 */
    public SMCue(msg) {
        this.WEB_ganPointX = Number(msg.point.x);
        this.WEB_ganPointY = Number(msg.point.y);
        this.SMshowGan();
        return;
        //------------------------------------------以下为测试转杆效果
        if (this.WEB_stageX == 0 && this.WEB_stageY == 0) {
            this.WEB_stageX = this.ganImg.x;
            this.WEB_stageY = this.ganImg.y;
            //起始位置
            this.WEB_ganPointX = this.WEB_stageX;
            this.WEB_ganPointY = this.WEB_stageY;
            this.SMshowGan();
        } else {
            if (this.WEB_stageX == Number(msg.point.x) && this.WEB_stageY == Number(msg.point.y)) {
                return;
            } else {
                //起始位置
                this.WEB_ganPointX = this.WEB_stageX;
                this.WEB_ganPointY = this.WEB_stageY;
                //终点
                this.WEB_stageX = Number(msg.point.x);
                this.WEB_stageY = Number(msg.point.y);
                Tween.removeTweens(this.ganImg);
                Tween.get(this, { onChange: this.SMshowGan, onChangeObj: this }).to({ factor: 1, factor1: 1 }, 1000);
            }
        }
    }
    public get factor(): number {
        return 0;
    }
    public set factor(value: number) {
        this.WEB_ganPointX = (1 - value) * (1 - value) * this.WEB_ganPointX + 2 * value * (1 - value) * this.WEB_stageY + value * value * this.WEB_stageX;
    }
    public get factor1(): number {
        return 0;
    }
    public set factor1(value: number) {
        this.WEB_ganPointY = (1 - value) * (1 - value) * this.WEB_ganPointY + 2 * value * (1 - value) * this.WEB_stageX + value * value * this.WEB_stageY;
    }
    /**显示杆的移动 */
    public SMshowGan() {
        var qx: number = this.curBall.nextX;
        var qy: number = this.curBall.nextY;

        var dx: number = this.WEB_ganPointX;
        var dy: number = this.WEB_ganPointY;

        var _a: number = dx - qx;
        var _b: number = dy - qy;
        var _c: number = Math.sqrt((dx - qx) * (dx - qx) + (dy - qy) * (dy - qy));

        var angle: number = 0;
        if (_a >= 0 && _b <= 0) {
            angle = Math.asin(_a / _c) * 180 / Math.PI - 90;
            this.angleSpeed = Math.asin(_a / _c);
            this.angleNum = 1;
            this.huadongAngle = this.angleSpeed - Math.PI / 2;
            this.ganImg.x = qx - (this.ganLen) * Math.sin(Math.asin(_a / _c));
            this.ganImg.y = qy + (this.ganLen) * Math.cos(Math.asin(_a / _c));
        }
        if (_a > 0 && _b > 0) {
            angle = (Math.asin(_b / _c)) * 180 / Math.PI;
            this.angleSpeed = Math.asin(_b / _c);
            this.angleNum = 2;
            this.huadongAngle = this.angleSpeed;
            this.ganImg.x = qx - (this.ganLen) * Math.cos((Math.asin(_b / _c)));
            this.ganImg.y = qy - (this.ganLen) * Math.sin((Math.asin(_b / _c)));
        }
        if (_b < 0 && _a < 0) {
            angle = Math.asin(_a / _c) * 180 / Math.PI - 90;
            this.angleSpeed = Math.asin(_a / _c);
            this.angleNum = 3;
            this.huadongAngle = this.angleSpeed - Math.PI / 2;
            this.ganImg.x = qx + (this.ganLen) * Math.sin(Math.asin(-_a / _c));
            this.ganImg.y = qy + (this.ganLen) * Math.cos(Math.asin(-_a / _c));
        }
        if (_a < 0 && _b > 0) {
            angle = (-(Math.asin(_b / _c) + 90 * Math.PI / 180)) * 180 / Math.PI - 90;
            this.angleSpeed = Math.asin(_b / _c);//球杆的角度
            this.angleNum = 4;
            this.huadongAngle = Math.PI - this.angleSpeed;
            this.ganImg.x = qx + (this.ganLen) * Math.cos(Math.asin(_b / _c));
            this.ganImg.y = qy - (this.ganLen) * Math.sin(Math.asin(_b / _c));
        }
        this.ganImg.rotation = angle;//改变度数
        this.ganImg.visible = true;
    }

    private SMHitPoint(msg) {

    }

    private SMHitAngle(msg) {

    }
    /**     word1	对方黑球进袋犯规，你赢了
            word2	黑球进袋犯规，你输了
            word3	击球超时
            word4	击球犯规，对方获得自由球
            word5	对方击球犯规，你获得自由球
            word6	你的回合
            word7	对方回合
            word8	8号球入袋，请重新开球
            word9	对方击球犯规，你获得线后自由球
            word10	击球犯规，对方获得线后自由球
            word11	您本局花色为全色
            word12	您本局花色为花色
            word13	进球成功，再来一杆
            word14	null
            word15	请摆放主球并开球
    
        */
    private isLosePrompt: boolean = false;
    private SMTableState(msg) {
    }
    /**给我的球加灯光特效 */
    public LighttoMyBalls() {
        if (this.myColor == 0) {//小号 全色
            this.addSmallBallLight();
        }
        if (this.myColor == 1) {//大号 花色
            this.addBigBallLight();
        }
        if (this.myColor == -1) { //未确定花色
            this.addBigBallLight();
            this.addSmallBallLight();
        }
        this.lighttoball8();
    }
    /**给小号球加灯光 */
    private addSmallBallLight() {
        for (var i: number = 0; i < this.ballArr.length; i++) {
            var ball: NewBall = this.ballArr[i];
            if (ball == undefined) { continue; }
            if (ball.idx >= 1 && ball.idx <= 7 && ball.isJindong != -2) {
                var dragonbonesData = RES.getRes("light3");
                var textureData = RES.getRes("light2");
                var texture = RES.getRes("light4_png");
                var dragonbonesFactory: dragonBones.EgretFactory = new dragonBones.EgretFactory();
                dragonbonesFactory.addDragonBonesData(dragonBones.DataParser.parseDragonBonesData(dragonbonesData));
                dragonbonesFactory.addTextureAtlas(new dragonBones.EgretTextureAtlas(texture, textureData));
                var armature: dragonBones.Armature = dragonbonesFactory.buildArmature("armatureName");
                this.addChild(armature.display);
                armature.display.x = ball.nextX;
                armature.display.y = ball.nextY;
                dragonBones.WorldClock.clock.add(armature);
                // armature.animation.gotoAndPlay("zq_guang_001a", -1, -1, 0);
                this.lightArr.push(armature);
                this.setGanOver(armature.display);
            }
        }
    }
    /**给大号球加灯光 */
    private addBigBallLight() {
        // console.log("addBigBallLight");
        for (var i: number = 0; i < this.ballArr.length; i++) {
            var ball: NewBall = this.ballArr[i];
            if (ball.idx >= 9 && ball.idx <= 15 && ball.isJindong != -2) {
                var dragonbonesData = RES.getRes("light3");
                var textureData = RES.getRes("light2");
                var texture = RES.getRes("light4_png");
                var dragonbonesFactory: dragonBones.EgretFactory = new dragonBones.EgretFactory();
                dragonbonesFactory.addDragonBonesData(dragonBones.DataParser.parseDragonBonesData(dragonbonesData));
                dragonbonesFactory.addTextureAtlas(new dragonBones.EgretTextureAtlas(texture, textureData));
                var armature: dragonBones.Armature = dragonbonesFactory.buildArmature("armatureName");
                this.addChild(armature.display);
                armature.display.x = ball.nextX;
                armature.display.y = ball.nextY;
                dragonBones.WorldClock.clock.add(armature);
                // armature.animation.gotoAndPlay("zq_guang_001a", -1, -1, 0);
                this.lightArr.push(armature);
                this.setGanOver(armature.display);
            }
        }
    }
    private lightImageArr: eui.Image[] = [];
    /**给大号球加灯光图片 */
    private addBigBallGuang() {
        for (var i: number = 0; i < this.ballArr.length; i++) {
            var ball: NewBall = this.ballArr[i];
            if (ball.idx >= 9 && ball.idx <= 15 && ball.isJindong != -2) {
                var t = new eui.Image("guang");
                this.addChild(t);
                t.x = ball.nextX;
                t.y = ball.nextY;
                t.width = 28;
                t.height = 28;
                this.lightImageArr.push(t);
            }
        }
    }

    /**给小号球加灯光图片 */
    private addSmallBallGuang() {
        for (var i: number = 0; i < this.ballArr.length; i++) {
            var ball: NewBall = this.ballArr[i];
            if (ball.idx >= 1 && ball.idx <= 7 && ball.isJindong != -2) {
                var t = new eui.Image("guang");
                this.addChild(t);
                t.x = ball.nextX;
                t.y = ball.nextY;
                t.width = 28;
                t.height = 28;
                this.lightImageArr.push(t);
            }
        }
    }

    private initguangArr() {

    }


    public PlayerEnter(msg) {
        if (Number(msg.playerState.account) == GameData.myAccount) {
            this.myChairId = msg.playerState.chair;
        }
        else {
            this.otherChairId = msg.playerState.chair;
        }
    }

    public SMGameStart(msg) {
        this.curActionNum = msg.nextChair;
        if (msg.nextChair == this.myChairId) {
            this.isOwnGame = true;
            this.isBaiqiu = 1;


            this.leftTurn.visible = true;
            this.rightTurn.visible = false;
        }
        else {
            this.isOwnGame = false;
            this.isBaiqiu = 1;

            this.leftTurn.visible = false;
            this.rightTurn.visible = true;
        }
        this.startGame1();
    }

    public swtichPosition(ball1, ball2) {
        //  console.log(ball1.idx + "123" + ball2.idx);



        ball1.lastX = ball2.lastX;
        ball1.lastY = ball2.lastY;
        ball1.nextX = ball2.nextX;
        ball1.nextY = ball2.nextY;



    }
    /**开始摆球*/
    public startGame1() {
        var standardpos = [0, 1, 12, 3, 9, 14, 4, 11, 5, 10, 13, 2, 15, 7, 6, 8];
        let ballTemp = [];//彩球
        this.curBall = new NewBall(0);
        this.curBall.nextY = this.curBall.lastY;
        this.curBall.lastX = -100;// this.posArr[0].hx + (this.posArr[2].hx - this.posArr[0].hx) * 0.1;
        this.curBall.lastY = -100;//this.posArr[0].hy + (this.posArr[3].hy - this.posArr[0].hy) / 2;
        this.curBall.nextX = -100; //this.curBall.lastX;
        this.curBall.nextY = -100;// this.curBall.lastY;
        this.curBall.name = "cur";
        this.ballArr.push(this.curBall);
        // ballTemp.push(this.curBall);
        this.otherX = this.posArr[0].hx + (this.posArr[2].hx - this.posArr[0].hx) * 0.7;
        this.otherY = this.posArr[0].hy + (this.posArr[3].hy - this.posArr[0].hy) / 2;


        //     var ballTemp: NewBall[] = [];//彩球

        for (var i: number = 0; i < 5; i++) {

            var ball: NewBall = new NewBall(this.ballArr.length);
            ball.lastX = this.otherX + (2 * ball.radius + 1) * i * Math.cos(Math.PI / 6);
            ball.lastY = this.otherY - (2 * ball.radius + 1) * i * Math.sin(Math.PI / 6);
            ball.nextX = ball.lastX;
            ball.nextY = ball.lastY;
            this.ballArr.push(ball);
            //     ballTemp.push(ball);
            for (var j: number = 1; j <= i; j++) {
                var ball1: NewBall = new NewBall(this.ballArr.length);
                ball1.lastX = ball.lastX;
                ball1.lastY = ball.lastY + 2 * ball1.radius * j + j;
                ball1.nextX = ball1.lastX;
                ball1.nextY = ball1.lastY;
                this.ballArr.push(ball1);
                //     ballTemp.push(ball1);
            }
        }


        for (var i = 0; i < this.ballArr.length; i++) {
            let ball1t = { lastX: 0, lastY: 0, nextX: 0, nextY: 0 };

            ball1t.lastX = this.ballArr[i].lastX;
            ball1t.lastY = this.ballArr[i].lastY;
            ball1t.nextX = this.ballArr[i].nextX;
            ball1t.nextY = this.ballArr[i].nextY;
            ballTemp.push(ball1t);
        }
        for (var i = 0; i < this.ballArr.length; i++) {
            let logNum = standardpos[i];
            this.swtichPosition(this.ballArr[i], ballTemp[logNum]);


        }




        for (var i: number = 0; i < this.ballArr.length; i++) {
            var ball: NewBall = this.ballArr[i];



            setBallPos1(ball.nextX, ball.nextY, i);
        }
        refreshUI();
        this.MyRange.touchEnabled = true;
        egret.setTimeout(this.startGame2, this, 1000 / 60);
        /**摆球结束执行自由球代码 */
        this.addEventListener(egret.Event.ENTER_FRAME, this.showWhiteBall, this);
    }
    /**初始化游戏控制 */
    private startGame2() {
        this._r = this.ballArr[0].radius;

        this.countdownTimer = new egret.Timer(1000, 0);
        this.countdownTimer.addEventListener(egret.TimerEvent.TIMER, this.startCountDown, this);

        this.golfBagTimer = new egret.Timer(1000 / 60, 0);
        this.golfBagTimer.addEventListener(egret.TimerEvent.TIMER, this.updataGolfBag, this);
        this.golfBagTimer.start();
        this.back.addEventListener(egret.TouchEvent.TOUCH_TAP, this.backMain, this);

        this.countdownFunc(true, 30);

        // this.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.setBaiPos, this);
        // this.addEventListener(egret.TouchEvent.TOUCH_MOVE, this.moveFunc, this);
        this.isCanMove = true;
        this.ganImg.visible = false;

        // var _spr1: egret.DisplayObject = this.getChildByName("dengdai");
        // if (_spr1.parent) {
        //     this.removeChild(_spr1);
        // }

        if (this.isLianxi == 1) {
            if (webNetworkMananger.getInstance().isMoving) {
                //发送表情
                // this.note.addEventListener(egret.TouchEvent.TOUCH_TAP, e => {
                //     webNetworkMananger.getInstance().sendFace(0);
                // }, this);


                this.stage.addEventListener(egret.Event.ACTIVATE, e => {
                    // webNetworkMananger.getInstance().dealWithBallSync();
                    console.log("游戏已从后台恢复");
                    TableUI._instance.BallArrToShow();
                    refreshUI();
                }, this);

            } else {
                //AI模式随机开杆顺序
                this.homeServer.randomOrder();
            }

        }
        //启用控件
        if (this.isLianxi == 2) {
            this.MyRound();
        }

    }


    private isCanMove: boolean = false;
    private removeAllEventListener() {
        this.removeEventListener(egret.Event.ENTER_FRAME, this.enterFrame, this);

        // this.removeEventListener(egret.TouchEvent.TOUCH_BEGIN, this.beginFunc, this);
        // this.removeEventListener(egret.TouchEvent.TOUCH_MOVE, this.moveFunc, this);
        // this.removeEventListener(egret.TouchEvent.TOUCH_END, this.endFunc, this);

        // this.lidudi.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.liduFunc, this);

        // this.removeEventListener(egret.TouchEvent.TOUCH_MOVE, this.moveWhiteball, this);

        this.countdownTimer.removeEventListener(egret.TimerEvent.TIMER, this.startCountDown, this);

        this.isCanMove = false;
        // this.TableUI.Instance().touchEnabled = false;
        // this.slip.touchEnabled = false;
        // this.lidudi .touchEnabled =false;

    }
    /**重置数据 */
    public restData() {
        this.myColor = -1;
        this.isOwnGame = false;
        GameData.roomId = null;
        GameData.rivalUserData = null;
        this.myLeg = false;
        webNetworkMananger.getInstance().intoBallIdxArr = [];
        this.golfBagTimer.removeEventListener(egret.TimerEvent.TIMER, this.updataGolfBag, this);
        this.golfBagTimer.stop();
        this.golfBag = [];
        this.baiBallIntoNow = false;
        this.blackBallIntoNow = false;
        this.firstCollision = -1;
        this.nowCombox = 0;
        this.isCanMove = false;
        this.iii = 0;
        webNetworkMananger.getInstance().serverBallPoint = [];
        this.back.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.backMain, this);
        webNetworkMananger.getInstance().isGameOver = false;
    }
    public quitFunc() {

        this.resetUI();
        this.restData();
        if (this.isLianxi == 1) {
            this.isCanClose = true;
        }

        this.isLianxi = 0;

        this.lianxiImg = new eui.Image("lianxiBtn1");
        this.lianxiImg.anchorOffsetX = 48;
        this.lianxiImg.x = this.centerX;
        this.lianxiImg.y = this.centerY + 170;
        this.addChild(this.lianxiImg);
        this.lianxiImg.name = "lianxi";
        this.lianxiImg.visible = false;

        var dragonbonesData = RES.getRes("ks3");
        var textureData = RES.getRes("ks2");
        var texture = RES.getRes("ks1");
        var dragonbonesFactory: dragonBones.EgretFactory = new dragonBones.EgretFactory();
        dragonbonesFactory.addDragonBonesData(dragonBones.DataParser.parseDragonBonesData(dragonbonesData));
        dragonbonesFactory.addTextureAtlas(new dragonBones.EgretTextureAtlas(texture, textureData));
        this.ksDragon = dragonbonesFactory.buildArmature("armatureName");
        this.ksDragon.display.name = "ks";
        this.addChild(this.ksDragon.display);
        this.isKsPlay = true;
        this.ksDragon.display.x = this.centerX;
        this.ksDragon.display.y = this.centerY + 80;
        dragonBones.WorldClock.clock.add(this.ksDragon);

        this.ksDragon.addEventListener(egret.Event.COMPLETE, function () {
            //dragonBones.WorldClock.clock.remove(_this.ksDragon);
            this.isKsBtn = true;
            this.isKsPlay = false;
            this.ksDragon.display.touchEnabled = true;
            this.ksDragon.display.addEventListener(egret.TouchEvent.TOUCH_TAP, this.startConnect, this);

            // this.lianxiImg.addEventListener(egret.TouchEvent.TOUCH_TAP, this.lianxiFunc, this);
        }.bind(this), this);
        this.ksDragon.animation.gotoAndPlay("zq_ks_01a", -1, -1, 1);

        if (this.isLianxi == 1) {
        }

        this.TrapezoidBallSide(this.trapezoid_Long, this.trapezoid_Middle, this.trapezoid_H);
        //画球案
        // this.debugDrawTable();

        this.InitShowBall();//初始化进球显示

        this.addGanEvt();//初始化击球力度

        this.whitei();//初始化瞄准球

        this.initBackAndVoice();//初始化返回及语音按钮

    }

    private SMTOPutBall(msg) {
        // if (this.whiteBall && this.whiteBall.parent) {
        //     this.removeChild(this.whiteBall);
        //     this.whiteBall = null;
        // }
        // if (this.xIcon && this.xIcon.parent) {
        //     this.removeChild(this.xIcon);
        //     this.xIcon = null;
        // }
        // this.isBaiqiu = 0;
        this.ClearW();
        this.curBall.isJindong = -1;
        this.curBall.lastX = this.curBall.nextX = Number(msg.ball.x);
        this.curBall.lastY = this.curBall.nextY = Number(msg.ball.y);
        // setBaiPos(msg.ball.x, msg.ball.y);
        // setBaiPos(msg.ball.x, msg.ball.y);
        refreshUI();
    }

    private isTOHit: boolean = false;
    /**联网击球 */
    public SMTOHit(msg) {
        this.isTOHit = true;
        this.countdownFunc(false);
        this.ClearAllLine();//清除瞄准线
        console.log("122")
        this.isOwnGame = false;
        this.isMove = true;
        this.isBegin = false;
        this.curBall.vx = msg.vx;
        this.curBall.vy = msg.vy;
        //-------------------------------------击球动画
        //球上一帧的坐标
        var oldx: number = this.ganImg.x;
        var oldy: number = this.ganImg.y;
        /**杆的反方向 */
        let negativeDirection: egret.Point = new egret.Point(this.ganImg.x, this.ganImg.y).subtract(new egret.Point(this.curBall.nextX, this.curBall.nextY));
        //球下一帧的移动坐标
        negativeDirection.normalize(125);
        var dx: number = oldx + negativeDirection.x;
        var dy: number = oldy + negativeDirection.y;
        //开始播放杆击球的动画
        var tw = egret.Tween.get(this.ganImg);
        tw.to({ x: dx, y: dy }, 100 * (1 - this.long / this.MaxPower));
        tw.to({ x: oldx, y: oldy }, 60 * (1 - this.long / this.MaxPower));
        tw.call(function () {
            this.isLoading = 2;
            this.ganImg.visible = false;
            this.long = 0;
            this.UpdateLiduLabel();
            // var channel: egret.SoundChannel = this.soundganqiu.play(0, 1);
            var v = Math.sqrt(msg.vx * msg.vx + msg.vy * msg.vy) / 2;
            this.PlaySoundWithVolume(v, TableUI.Instance().shootSound);
            // if (v > 1) v = 1;
            // //channel.volume = v;
            // channel.volume = Math.sqrt(msg.vx * msg.vx + msg.vy * msg.vy) / 2;
            this.addEventListener(egret.Event.ENTER_FRAME, this.enterFrame, this);
        }, this)

        this.ld.visible = false;
        this.slipgroup.visible = false;
    }

    public countdownFunc(b: boolean, _num: number = 0) {
        if (b && _num > 0) {
            var num = Math.floor(_num);
            this.curTimerNum = num;
            if (!this.countdownTimer.running) {
                this.countdownTimer.start();
            }
        }
        if (!b) {
            this.curTimerNum = 0;
            if (this.countdownTimer.running) {
                this.countdownTimer.stop();
            }
            this.setTimeNum(this.curTimerNum);
        }
    }

    /**计时及超时触发 */
    private startCountDown() {
        if (!this.stop) {
            this.curTimerNum--;
            if (webNetworkMananger.getInstance().isMoving && this.isLianxi == 1) {
                if (webNetworkMananger.getInstance().isMyLeg) {
                    this.lightning(0);
                } else {
                    this.lightning(1);
                }
            } else if (!webNetworkMananger.getInstance().isMoving && this.isLianxi == 1) {
                if (FakeServerManage.getInstance().nowShoot == -1) {
                    this.lightning(0);
                } else if (FakeServerManage.getInstance().nowShoot == 1) {
                    this.lightning(1);
                }
            }
            else if (this.isLianxi == 2) {
                let random: number = Math.random();
                if (random > 0.5) {
                    this.lightning(0);
                } else {
                    this.lightning(1);
                }
            }
        }
        this.setTimeNum(this.curTimerNum);
        // console.log("计时器", this.curTimerNum);
        if (!webNetworkMananger.getInstance().isMoving && this.isLianxi == 1) {//不执行0.0
            if (this.curTimerNum == 0) {
                this.countdownTimer.stop();
                if (this.isBaiqiu == 0) {
                    this.homeServer.exchangeBall(false, 1);//我超时后 AI线后自由球
                } else {
                    this.homeServer.exchangeBall(false, this.isBaiqiu);
                }
                this.setSour('word3');
                console.log("超时");
                changeBG("resource/assets/bg/table.png");//初始背景
                this.ClearAllLine();
                this.isBaiqiu == 0;
                this.ClearW();
                if (this.homeServer.nowShoot == 1) {
                    this.isOwnGame = false;
                    this.ClearAllLine();
                }
                // this.MyRange.touchEnabled = false;//禁止玩家操作
                // this.removeAllEventListener();//禁止玩家操作
            }
        }
    }
    /**再来一局 */
    public againFunc() {
        this.resetUI();
        this.restData();
        if (this.isLianxi == 1) {
            this.isOwnGame = false;
            this.setSour('Waiting for another Game Start...');
            if (this.isLianxi == 1) {//联机模式
                if (webNetworkMananger.getInstance().isMoving) {//匹配
                    if (webNetworkMananger.getInstance().isConnecteed) {
                        webNetworkMananger.getInstance().onSocketOpen();
                    } else {
                        webNetworkMananger.getInstance().connect();
                    }
                } else {//AI模式
                    egret.setTimeout(this.startGame1, this, 1000 / 60);
                    egret.setTimeout(this.homeServer.randomOrder, this, 1000 / 60);//随机开杆
                    // this.homeServer.randomOrder();
                }
            }
        }
        else if (this.isLianxi == 2) {
            this.isOwnGame = true;
            this.isBaiqiu = 1;
            this.setSour('Waiting for once more practice Start...');
            egret.setTimeout(this.startGame1, this, 1000 / 60);
        }
    }

    //刷新界面
    private resetUI() {
        this.removeAllEventListener();

        for (var i: number = this.ballArr.length - 1; i >= 0; i--) {
            remove3DBall(i);
            this.ballArr.splice(i, 1);
        }
        refreshUI();

        Refresh3DBall();

        this.isMove = false;
        this.isBegin = false;
        this.isOwnGame = false;
        this.otherChairId = -1;
        this.curActionNum = 0;
        this.myColor = -1;

        this.InitShowBall();//初始化进球显示

        this.ClearAllLine();//清除所有瞄准线以及灯光

        this.ganImg.visible = false;

        this.long = 0;
        this.UpdateLiduLabel();
    }
    private showTips(e: egret.TouchEvent) {
        if (!this.tipsUI.parent) {
            this.tipsUI.anchorOffsetX = 212;
            this.tipsUI.anchorOffsetY = 58;
            this.tipsUI.x = e.target.x;
            this.tipsUI.y = e.target.y;
            this.tipsUI.dingshi();
            this.addChild(this.tipsUI);
        }

    }

    public SMHit(msg) {
        this.countdownFunc(false);
        this.ganImg.visible = false;
        this.curBall.vx = Number(msg.vx);
        this.curBall.vy = Number(msg.vy);
        // this.isLoading = 2;
        this.addEventListener(egret.Event.ENTER_FRAME, this.enterFrame, this);
    }

    private static _instance: TableUI = null;

    public static Instance(): TableUI {
        if (TableUI._instance == null) {
            TableUI._instance = new TableUI();
        }
        return TableUI._instance;
    }

    //鼠标 移动时触发 获取鼠标在屏幕内的坐标
    private mouseMoveGan(evt: MouseEvent) {
        if (TableUI.Instance().isKsBtn) {
            TableUI.Instance().playKsAction(evt.pageX, evt.pageY);
        }
        // if (TableUI.Instance().isCanMove) {
        //     if (!TableUI.Instance().istouchsp) {
        //         TableUI.Instance().moveGan(evt.pageX, evt.pageY);//固定鼠标位置即可使用细准焦螺旋
        //         document.addEventListener("keydown", function (e: any) {
        //             if (e.keyCode == 13 && !TableUI.Instance().isMove) {
        //                 TableUI.Instance().XX = evt.pageX;
        //                 TableUI.Instance().YY = evt.pageY;
        //                 TableUI.Instance().istouchsp = true;
        //             }
        //         });
        //     }
        // }
    }
    private isKsPlay: boolean = false;
    private playKsAction(_x: number, _y: number) {
        var mPX: number = 0;
        var mPY: number = 0;
        if (bep == 0) {
            mPX = _rate * _x;
            mPY = _rate * (_y - bel);
        } else if (bep == 1) {
            mPX = _rate * (_x - bel);
            mPY = _rate * _y;
        }
        var _x = this.centerX;
        var _y = this.centerY + 80;
        //鼠标滑过"开始"按钮时的特效
        if (mPX >= _x - 80 && mPY >= _y - 80 && mPX <= _x + 80 && mPY <= _y + 80) {
            if (!this.isKsPlay) {
                this.isKsPlay = true;
                console.log("play");
                this.ksDragon.animation.gotoAndPlay("zq_ks_02a", -1, -1, 0);
            }
        }
        else {
            if (this.isKsPlay) {
                this.ksDragon.animation.gotoAndStop("zq_ks_02a", 0, );

                this.isKsPlay = false;
                console.log("over");
            }
        }
        //鼠标滑过按钮时的效果
        if (mPX >= this.lianxiImg.x - 48 && mPX <= this.lianxiImg.x + 48 && mPY >= this.lianxiImg.y && mPY <= this.lianxiImg.y + 41) {
            if (this.lianxiImg.source == 'lianxiBtn1') {
                this.lianxiImg.source = 'lianxiBtn2';
            }
        } else {
            if (this.lianxiImg.source == 'lianxiBtn2') {
                this.lianxiImg.source = 'lianxiBtn1';
            }
        }
    }
    public moveGan(mPX: number, mPY: number) {
        if (this.isBaiqiu != 0) return;
        //console.log(this.ganImg.rotation, "杆的旋转");
        // console.log("鼠标X", mPX, "鼠标Y", mPY);
        // console.log("细改变的值", this.slipsize);
        if ((this.ganImg.rotation > -45 && this.ganImg.rotation < 45) ||
            (this.ganImg.rotation < -135 && this.ganImg.rotation > -180) ||
            ((this.ganImg.rotation > 135 && this.ganImg.rotation < 180))) { //横杆
            mPY += this.slipsize;
        } else {//竖杆
            mPX += this.slipsize;
        }
        // console.log("_x : ", _x, "_y : ", _y, "_rate : ", _rate);
        if (!this.isOwnGame) {
            return;
        }
        // if (this.isBaiqiu != 0) {
        //     // var mPX: number = 0;
        //     // var mPY: number = 0;
        //     // if (bep == 0) {
        //     //     mPX = _rate * _x;
        //     //     mPY = _rate * (_y - bel);
        //     // } else if (bep == 1) {
        //     //     mPX = _rate * (_x - bel);
        //     //     mPY = _rate * _y;
        //     // }
        //     if (mPX >= 116 && mPY >= 31 && mPX <= 1311 && mPY <= 683) {
        //         if (this.whiteBall == null) {
        //             this.whiteBall = new eui.Image("whiteBall");
        //             this.whiteBall.anchorOffsetX = 109 / 2;
        //             this.whiteBall.anchorOffsetY = 109 / 2;
        //             this.addChild(this.whiteBall);

        //             this.curBall.lastX = this.curBall.nextX = -17;
        //             this.curBall.lastY = this.curBall.nextY = -17;
        //             this.curBall.vx = 0;
        //             this.curBall.vy = 0;
        //             setBaiPos(-17, -17);
        //             refreshUI();
        //         }
        //         if (this.isBaiqiu == 1) {
        //             if (mPX > 400) {//划线
        //                 if (this.xIcon == null) {
        //                     this.xIcon = new eui.Image("forbid");
        //                     this.xIcon.anchorOffsetX = 109 / 2;
        //                     this.xIcon.anchorOffsetY = 109 / 2;
        //                     this.addChild(this.xIcon);
        //                 }
        //                 this.xIcon.x = mPX;
        //                 this.xIcon.y = mPY;
        //             }
        //             else {
        //                 if (this.xIcon && this.xIcon.parent) {
        //                     this.removeChild(this.xIcon);
        //                     this.xIcon = null;
        //                 }
        //             }
        //         }
        //         this.whiteBall.x = mPX;
        //         this.whiteBall.y = mPY;
        //     }
        //     return;
        // }
        // if (!this.isMove && !this.isBegin) {
        // var mPX: number = 0;
        // var mPY: number = 0;
        // if (bep == 0) {
        //     mPX = _rate * _x;
        //     mPY = _rate * (_y - bel);
        // } else if (bep == 1) {
        //     mPX = _rate * (_x - bel);
        //     mPY = _rate * _y;
        // }

        // if (mPX >= 116 && mPY >= 31 && mPX <= 1311 && mPY <= 683) {
        var dx: number = mPX - this.curBall.nextX;
        var dy: number = mPY - this.curBall.nextY;
        var dist: number = Math.sqrt(dx * dx + dy * dy);
        if (dist <= this._r) {
            return;
        }
        //显示球杆的旋转
        this.showGan(mPX, mPY);
        this.setSubline();
        //this.setSubline1();
        if (this.isLianxi == 1) {
            var curTime: number = egret.getTimer();
            if (curTime - this.moveTime > 100) {
                this.moveTime = curTime;
                var moveGanData = {
                    point: { x: mPX, y: mPY },
                    angle: this.ganImg.rotation
                }
                if (webNetworkMananger.getInstance().isMoving) {
                    webNetworkMananger.getInstance().SendMoveMeesage(moveGanData);
                }
            }
            // }

        }
    }

    public rotationCoord(_x: number, _y: number, __angele) {
        if (__angele == 0) {
            __angele = 0.0001;
        }
        var radian: number = -__angele;
        var a: number = Math.cos(radian) * Math.cos(radian) / Math.sin(radian) + Math.sin(radian);
        var x: number = ((Math.cos(radian) * _x) / Math.sin(radian) - _y) / a;
        // var x:number=Math.cos(radian)*_x-Math.sin(radian)*_y;
        var b: number = Math.cos(radian) + Math.sin(radian) * Math.sin(radian) / Math.cos(radian);
        var y: number = ((Math.sin(radian) * _x) / Math.cos(radian) + _y) / b;
        //var y:number=(Math.sin(radian)*_x+Math.cos(radian)*_y);
        return { x: x, y: y }
    }
    /**显示杆的移动 */
    public showGan(_x: number, _y: number) {
        var qx: number = this.curBall.nextX;
        var qy: number = this.curBall.nextY;

        var dx: number = _x;
        var dy: number = _y;

        var _a: number = dx - qx;
        var _b: number = dy - qy;
        var _c: number = Math.sqrt((dx - qx) * (dx - qx) + (dy - qy) * (dy - qy));

        var angle: number = 0;
        if (_a >= 0 && _b <= 0) {
            angle = Math.asin(_a / _c) * 180 / Math.PI - 90;
            this.angleSpeed = Math.asin(_a / _c);
            this.angleNum = 1;
            this.huadongAngle = this.angleSpeed - Math.PI / 2;
            this.ganImg.x = qx - (this.ganLen) * Math.sin(Math.asin(_a / _c));
            this.ganImg.y = qy + (this.ganLen) * Math.cos(Math.asin(_a / _c));
        }
        if (_a > 0 && _b > 0) {
            angle = (Math.asin(_b / _c)) * 180 / Math.PI;
            this.angleSpeed = Math.asin(_b / _c);
            this.angleNum = 2;
            this.huadongAngle = this.angleSpeed;
            this.ganImg.x = qx - (this.ganLen) * Math.cos((Math.asin(_b / _c)));
            this.ganImg.y = qy - (this.ganLen) * Math.sin((Math.asin(_b / _c)));
        }
        if (_b < 0 && _a < 0) {
            angle = Math.asin(_a / _c) * 180 / Math.PI - 90;
            this.angleSpeed = Math.asin(_a / _c);
            this.angleNum = 3;
            this.huadongAngle = this.angleSpeed - Math.PI / 2;
            this.ganImg.x = qx + (this.ganLen) * Math.sin(Math.asin(-_a / _c));
            this.ganImg.y = qy + (this.ganLen) * Math.cos(Math.asin(-_a / _c));
        }
        if (_a < 0 && _b > 0) {
            angle = (-(Math.asin(_b / _c) + 90 * Math.PI / 180)) * 180 / Math.PI - 90;
            this.angleSpeed = Math.asin(_b / _c);//球杆的角度
            this.angleNum = 4;
            this.huadongAngle = Math.PI - this.angleSpeed;
            this.ganImg.x = qx + (this.ganLen) * Math.cos(Math.asin(_b / _c));
            this.ganImg.y = qy - (this.ganLen) * Math.sin(Math.asin(_b / _c));
        }
        this.ganImg.rotation = angle;//改变度数
        this.ganImg.visible = true;
    }
    private isClickLidu: boolean = false;

    /**放白球*/
    public beginFunc() {
        if (!this.isOwnGame) {
            return;
        }
        if (this.isBaiqiu == 0) {
            return;
        }
        let mpx = this.whiteBall.x;
        let mpy = this.whiteBall.y;
        if (mpx >= 116 && mpy >= 31 && mpx <= 1311 && mpy <= 683) {
            if (this.isBaiqiu != 0) {
                var num: number = 0;
                if (this.isBaiqiu == 1) {
                    num = 400 + this._r;//划线
                }
                else if (this.isBaiqiu == 2) {
                    num = this.posArr[2].x2;
                }
                if (mpx > this.posArr[0].x2 + this._r && mpy > this.posArr[0].y1 + this._r && mpx < num - this._r && mpy < this.posArr[3].y2 - this._r) {
                    for (var i: number = 0; i < 6; i++) {
                        var _hx: number = this.posArr[i].hx;
                        var _hy: number = this.posArr[i].hy;
                        if (mpx > _hx - this.holeR && mpx < _hx + this.holeR && mpy > _hy - this.holeR && mpy < _hy + this.holeR) {
                            var dx: number = mpx - _hx;
                            var dy: number = mpy - _hy;
                            var dist: number = Math.sqrt(dx * dx + dy * dy);
                            if (dist < this.holeR) {
                                //放到洞上了
                                this.setSour("word15");
                                return;
                            }
                        }
                    }
                    //检查是否与球相交
                    if (this.CheckBallCollision(mpx, mpy)) {
                        this.setSour("word15");
                        return;
                    }
                    // for (var j: number = 0; j < this.ballArr.length; j++) {
                    //     var ballA: NewBall = this.ballArr[j];
                    //     if (ballA.name == "cur") {
                    //         continue;
                    //     }
                    //     var dx: number = ballA.nextX - mpx;
                    //     var dy: number = ballA.nextY - mpy;
                    //     var dist: number = Math.sqrt(dx * dx + dy * dy);
                    //     if (dist <= 2 * this._r) {//放到球上了
                    //         return;
                    //     }
                    // }

                    if (this.isLianxi == 1) {
                        if (webNetworkMananger.getInstance().isMoving) {
                            webNetworkMananger.getInstance().sendPutBallMsg({ x: mpx, y: mpy });
                            //console.log("摆球位置:" + mpx + "   " + mpy);
                        }
                    }
                    console.log("摆球位置:" + mpx + "   " + mpy);
                    setBaiPos(mpx, mpy);
                    changeBG("resource/assets/bg/table.png");//初始背景
                    refreshUI();
                    this.curBall.lastX = this.curBall.nextX = mpx;
                    this.curBall.lastY = this.curBall.nextY = mpy;
                    this.ClearW();
                    this.curBall.isJindong = -1;
                    this.isBaiqiu = 0;
                }
                else {
                    this.setSour("word15");
                    return;
                }
                return;
            }
        }

        if (!this.isMove && !this.isBegin) {
            if (mpx >= 116 && mpy >= 31 && mpx <= 1311 && mpy <= 683) {
                var dx: number = mpx - this.curBall.nextX;
                var dy: number = mpy - this.curBall.nextY;
                console.log("123")
                var dist: number = Math.sqrt(dx * dx + dy * dy);
                if (dist <= this._r) {
                    return;
                }



                if (this.isLianxi == 1) {

                }

                this.isBegin = true;
                if (!this.isClickLidu) {
                    this.long = 0;
                    this.UpdateLiduLabel();
                }
                else {
                    this.isClickLidu = false;
                }

                this.addNum = 2;

                this.isLoading = 0;
                // this.addEventListener(egret.Event.ENTER_FRAME, this.enterFrame, this);
                // this.liduTime = egret.setTimeout(function () {
                //     this.isLoading = 1;
                // }, this, 500);
                return;
            }
        }
    }
    public promptWord: PromptWord;
    // private liduTime: number = 0;
    // private moveFunc(e: egret.TouchEvent) {

    // }
    /**exchangeBall击球 */
    public shootBall(vigor, ganPoint: egret.Point) {
        //确定击球的力度
        var speed: number = 2 * vigor / this.MaxPower;
        //判断发射角度象限
        if (this.angleNum == 1) {
            this.curVx = speed * Math.sin(this.angleSpeed);
            this.curVy = -speed * Math.cos(this.angleSpeed);
        }
        else if (this.angleNum == 2) {
            this.curVx = speed * Math.cos(this.angleSpeed);
            this.curVy = speed * Math.sin(this.angleSpeed);
        }
        else if (this.angleNum == 3) {
            this.curVx = speed * Math.sin(this.angleSpeed);
            this.curVy = -speed * Math.cos(this.angleSpeed);
        }
        else if (this.angleNum == 4) {
            this.curVx = -speed * Math.cos(this.angleSpeed);
            this.curVy = speed * Math.sin(this.angleSpeed);
        }
        this.ClearAllLine();//清除瞄准线
        //给白球加速度
        this.curBall.vx = this.curVx;
        this.curBall.vy = this.curVy;
        //结束我的回合 球开始移动 我的游戏结束
        this.isOwnGame = false;
        this.isMove = true;
        this.isBegin = false;

        this.countdownFunc(false);

        // egret.clearTimeout(this.liduTime);
        this.isLoading = 0;
        //球上一帧的坐标
        var oldx: number = this.ganImg.x;
        var oldy: number = this.ganImg.y;
        //球下一帧的移动坐标
        ganPoint.normalize(vigor);
        var dx: number = oldx + ganPoint.x;
        var dy: number = oldy + ganPoint.y;
        // //球的弧度（反映球的移动方向,画布坐标系）
        // var angle: number = Math.atan2(dy, dx);
        // var sin: number = Math.sin(angle);
        // var cos: number = Math.cos(angle);

        // var pos0: egret.Point = new egret.Point(0, 0);
        // pos0.x -= 80 * this.long / this.MaxPower;
        // var pos0F: any = this.rotateR(pos0.x, pos0.y, sin, cos, false);

        // var newOldx = oldx + pos0F.x;
        // var newOldy = oldy + pos0F.y;
        //开始播放杆击球的动画
        var tw = egret.Tween.get(this.ganImg);
        tw.to({ x: dx, y: dy }, 1000 * (1 - this.long / this.MaxPower));
        tw.to({ x: oldx, y: oldy }, 600 * (1 - this.long / this.MaxPower));
        tw.call(function () {
            this.isLoading = 2;
            this.ganImg.visible = false;
            this.long = 0;
            this.UpdateLiduLabel();
            // var channel: egret.SoundChannel = this.soundganqiu.play(0, 1);
            var v = Math.sqrt(this.curVx * this.curVx + this.curVy * this.curVy) / 2;
            this.PlaySoundWithVolume(v, TableUI.Instance().shootSound);
            // if (v > 1) v = 1;
            // //channel.volume = v;
            this.addEventListener(egret.Event.ENTER_FRAME, this.enterFrame, this);
        }, this)


        this.ld.visible = false;
        this.slipgroup.visible = false;
    }
    private endFunc() {
        if (!this.isOwnGame || this.long < 1) {
            return;
        }
        // if (!this.isMove && this.isBegin) 
        {
            //确定击球的力度
            var speed: number = 2 * this.long / this.MaxPower;
            //判断发射角度象限
            if (this.angleNum == 1) {
                this.curVx = speed * Math.sin(this.angleSpeed);
                this.curVy = -speed * Math.cos(this.angleSpeed);
            }
            else if (this.angleNum == 2) {
                this.curVx = speed * Math.cos(this.angleSpeed);
                this.curVy = speed * Math.sin(this.angleSpeed);
            }
            else if (this.angleNum == 3) {
                this.curVx = speed * Math.sin(this.angleSpeed);
                this.curVy = -speed * Math.cos(this.angleSpeed);
            }
            else if (this.angleNum == 4) {
                this.curVx = -speed * Math.cos(this.angleSpeed);
                this.curVy = speed * Math.sin(this.angleSpeed);
            }
            this.ClearAllLine();//清除瞄准线
            //给白球加速度
            this.curBall.vx = this.curVx;
            this.curBall.vy = this.curVy;
            //结束我的回合 球开始移动 我的游戏结束
            this.isOwnGame = false;
            this.isMove = true;
            this.isBegin = false;
            //联网预留 发送击球信号 应包含（this.curBall.vx,this.curBall.vy,this.angelSpeed,）
            if (this.isLianxi == 1) {
                if (webNetworkMananger.getInstance().isMoving) {
                    webNetworkMananger.getInstance().SendShootMeesage({ vx: this.curVx, vy: this.curVy })
                } else {

                }
            }

            this.countdownFunc(false);

            // egret.clearTimeout(this.liduTime);
            this.isLoading = 0;
            //球上一帧的坐标
            var oldx: number = this.ganImg.x;//this.GetGanDir().x;
            var oldy: number = this.ganImg.y;//this.GetGanDir().y;
            //球下一帧的移动坐标
            var dx: number = this.curBall.nextX - oldx;
            var dy: number = this.curBall.nextY - oldy;
            //球的弧度（反映球的移动方向,画布坐标系）
            var angle: number = Math.atan2(dy, dx);
            var sin: number = Math.sin(angle);
            var cos: number = Math.cos(angle);

            var pos0: egret.Point = new egret.Point(0, 0);
            pos0.x -= 80 * this.long / this.MaxPower;
            var pos0F: any = this.rotateR(pos0.x, pos0.y, sin, cos, false);

            var newOldx = oldx + pos0F.x;
            var newOldy = oldy + pos0F.y;
            //开始播放杆击球的动画
            var tw = egret.Tween.get(this.ganImg);
            tw.to({ x: newOldx, y: newOldy }, 10 * (1 - this.long / this.MaxPower));
            tw.to({ x: oldx, y: oldy }, 6 * (1 - this.long / this.MaxPower));
            tw.call(function () {
                this.isLoading = 2;
                this.ganImg.visible = false;
                this.long = 0;
                this.UpdateLiduLabel();
                // var channel: egret.SoundChannel = this.soundganqiu.play(0, 1);
                var v = Math.sqrt(this.curVx * this.curVx + this.curVy * this.curVy) / 2;
                this.PlaySoundWithVolume(v, TableUI.Instance().shootSound);
                // if (v > 1)
                //     v = 1;
                // //channel.volume = v;
                this.addEventListener(egret.Event.ENTER_FRAME, this.enterFrame, this);
            }, this)
            this.ld.visible = false;
            this.slipgroup.visible = false;
        }
    }

    private addNum: number = 2;
    private enterFrame() {

        if (this.isLoading == 2) {
            this.updataMask();
            refreshUI();
        }

    }
    /**连杆计数 */
    public numii: number = 0;
    /**更新球袋 */
    public updataGolfBag() {
        /**是否刷新UI */
        let isRefresh: boolean = false;
        /**停止球的数量 */
        let stopNumber: number = 0;
        if (this.golfBag == null) {
            return;
        }
        if (this.golfBag.length > 0) {
            //球袋数量超出从下面减少一个
            if (this.golfBag.length > 13) {
                let ballSub: number = webNetworkMananger.getInstance().findBall(this.golfBag[0].idx, this.ballArr);
                this.golfBag[0].nextX = -100;
                this.golfBag[0].nextY = -100;
                this.golfBag[0].vy = 0;
                this.golfBag[0].vx = 0;
                setBallPos1(this.golfBag[0].nextX, this.golfBag[0].nextY, ballSub);
                this.golfBag.splice(0, 1);
            }
            for (var i: number = 0; i < this.golfBag.length; i++) {
                /**球袋的球 */
                let ball: NewBall = this.golfBag[i];
                /**球的本地下标 */
                let ballSub: number = webNetworkMananger.getInstance().findBall(ball.idx, this.ballArr);

                if (ball.nextY >= 620 - this._r * 2 * i) {
                    // console.log("124")
                    ball.nextY = 620 - this._r * 2 * i;
                    setBallPos1(ball.nextX, ball.nextY, ballSub);
                    ball.vy = 0;
                    ball.vx = 0;
                    stopNumber++;
                    //this.golfBag.splice(i, 1);
                    //this.golfBagNum++;
                    continue;
                } else {
                    if (ball.nextX >= 1234) {
                        if (ball.vy == 0) {
                            ball.vy = 3;
                            ball.vx = 0;
                        }
                    }
                }
                if (ball.nextX < 0 || ball.nextY < 0) {
                    if (this.golfBag.length > 1 && this.golfBag[i - 1].nextX < 1234) {
                        continue;
                    }
                    ball.nextX = 1196;
                    ball.nextY = 180;
                    ball.vy = 0.6;
                    ball.vx = 3;
                }
                if (ball.nextX > 1234) {
                    ball.nextX = 1234;
                    ball.vy = 3;
                    ball.vx = 0;
                }

                if (ball.vx != 0 || ball.vy != 0) {
                    if (ball.nextX >= 1234) {
                        ball.vy += 0.3;
                        // console.log(ball.vy);
                        if (ball.vx >= 10) {
                            ball.vx == 10;
                            ball.vy == 10;
                        }
                    }
                    ball.nextX += ball.vx;
                    ball.nextY += ball.vy;

                    setBallPos(ball.nextX, ball.nextY, ball.lastX, ball.lastY, ballSub);
                    refreshUI();
                    isRefresh = true;

                    ball.lastX = ball.nextX;
                    ball.lastY = ball.nextY;

                }
            }
            if (stopNumber == this.golfBag.length) {
                this.isGolfBagRoll = false;
            } else {
                this.isGolfBagRoll = true;
            }


        }

    }






    /**上一回合击球的玩家ID */
    public lastshoot: number;
    /**是否交换了 */
    private ischanged: boolean = false;
    /**目前的连进数 */
    public nowCombox: number = 0;


    /**获取当前击球玩家的花色 */
    private getnowshootcolor(): number {
        var n: number = -1;

        if (webNetworkMananger.getInstance().isMoving && this.isLianxi == 1) {
            if (this.myLeg) {
                n = this.myColor;
            }
            else {
                switch (this.myColor) {
                    case 1://实心
                        n = 0;
                        break;
                    case 0://花色
                        n = 1;
                        break;
                    default:
                        n = -1;
                        break;
                }
            }
        } else {
            if (this.isLianxi == 1) {
                n = this.homeServer.getNowLegShootColor();
            }
        }


        return n;
    }


    private updataMask() {
        for (var u: number = 0; u < 30; u++) {
            var len: number = this.ballArr.length;//所有球的数组
            var num: number = 0;//已静止的球
            /**所有球 */
            for (var i: number = len - 1; i >= 0; i--) {
                var ball: NewBall = this.ballArr[i];
                if (ball.vx == 0 && ball.vy == 0 && ball.isJindong == -1) {
                    num++;
                }
                if (ball.vx == 0 && ball.vy == 0 && ball.isJindong == -2) {
                    num++;
                }
                if (ball.isJindong != -1 && ball.isJindong != -2) {

                    //绕洞旋转效果
                    var pt: egret.Point = egret.Point.polar(11, ball.degree * Math.PI / 180);
                    ball.nextX = this.posArr[ball.isJindong].hx + pt.x;
                    ball.nextY = this.posArr[ball.isJindong].hy + pt.y;
                    ball.degree += 0.6;



                    if (ball.degree >= 300 && ball.degree < 300.6) {
                        //绕洞旋转结束
                        this.jinqiuAction(ball.isJindong);//龙骨



                    }//进球结束





                    if (ball.degree >= 600) {
                        if (ball.name != "cur" && ball.idx != 8 && ball.name != "black") {
                            this.removeBallArr.push(ball.idx);
                        }
                        if (ball.name == "cur") {
                            ball.nextX = -17;
                            ball.nextY = -17;
                            ball.isJindong = -1;
                        } else if (ball.name == "black") {
                            ball.nextX = 400;
                            ball.nextY = 400;
                            ball.isJindong = -1;
                        } else {
                            //remove3DBall(i);
                            //this.ballArr.splice(i, 1);
                            ball.nextX = -50;
                            ball.nextY = -50;
                            ball.vx = 0;
                            ball.vy = 0;
                            ball.isJindong = -2;
                            setBallPos1(ball.nextX, ball.nextY, i);
                            this.golfBag.push(ball);
                            if (this.ballImgArr[ball.idx - 1]) {
                                this.ballImgArr[ball.idx - 1].alpha = 1;
                            }
                        }
                    }
                }
                else {
                    if (ball.isJindong != -2) {
                        if (ball.vx != 0 || ball.vy != 0) {
                            ball.nextX += ball.vx;
                            ball.nextY += ball.vy;
                            ball.startRoll();
                            this.checkWalls(ball);
                            //this.checkWalls1(ball);
                        }
                    }
                }
            }

            var len: number = this.ballArr.length;
            for (i = 0; i < len - 1; i++) {
                var ballA: NewBall = this.ballArr[i];
                if (ballA.isJindong != -1) {
                    continue;
                }
                for (var j: number = i + 1; j < len; j++) {
                    var ballB: NewBall = this.ballArr[j];
                    if (ballB.isJindong != -1) {
                        continue;
                    }
                    this.checkCollision(ballA, ballB);//碰撞检测 (第一个球)
                }
            }
            if (len == num && !this.isGolfBagRoll) {
                this.isLoading = 0;
                this.removeEventListener(egret.Event.ENTER_FRAME, this.enterFrame, this);
                this.slipsize = 0;//微调复位
                //红点复位
                this.white.x = 393;
                this.white.y = 158;
                this.red.x = 623;
                this.red.y = 383;

                this.ballpoint.x = this.red.x * 0.08 + this.mx - 50;
                this.ballpoint.y = this.red.y * 0.1 + this.my - 35;
                console.log("回合结束");
                // if (webNetworkMananger.getInstance().isMoving && this.isLianxi == 1) {
                //     if (!this.isComBoPK) {
                //         this.numii = 0;
                //         console.log("计数清零000回合结束");
                //     }
                // }

                if (this.isLianxi == 2) {
                    this.ld.visible = true;
                    this.slipgroup.visible = true;
                    this.MyRange.touchEnabled = true;
                }

                // this.seeAboutSurplus(this.getnowshootcolor(), this.ballArr);
                this.showGan(this.XX, this.YY);
                this.long = 0;
                if (this.isLianxi == 2)
                    this.countdownFunc(true, 30);
                this.UpdateLiduLabel();
                this.addGanEvt();
                for (var i: number = this.ballArr.length - 1; i >= 0; i--) {//重置所有球的属性
                    var b: NewBall = this.ballArr[i];
                    if (b.isJindong == -2) {
                        continue;
                    }
                    b.moc = 0.9997;
                    b.degree = 0;
                    b.isJindong = -1;
                }

                if (this.isLianxi == 1) {
                    /**球的数组 */
                    var tableArr: any[] = [];
                    for (var i: number = 0; i < this.ballArr.length; i++) {
                        this.ballArr[i].nextX = Math.round(this.ballArr[i].nextX);
                        this.ballArr[i].nextY = Math.round(this.ballArr[i].nextY);
                        tableArr.push(this.ballArr[i]);
                    }
                    // console.log("第一个碰的球号为:" + this.firstCollision)

                    //击球判定           
                    if (webNetworkMananger.getInstance().isMoving) {//真人对决判定
                        if (this.blackBallIntoNow) {
                            webNetworkMananger.getInstance().isGameOver = true;
                        }
                        if (this.myLeg) {   //我的回合
                            if (this.firstCollision != 0) { //本回合碰到球
                                if (this.iiiNow > 0) {      //进球了
                                    if (this.blackBallIntoNow) {    //黑球进洞
                                        if (this.isFirstLeg) {//首杆黑8进球
                                            this.shootBallMsgShow("首杆黑8进球，对方线后自由球");
                                            webNetworkMananger.getInstance().SendShootEndMeesage(1, GameData.rivalUserData.userId);
                                        } else {//首杆黑8未进球


                                            if (this.myColor == -1) {   //没确定花色
                                                //我方失败
                                                this.shootBallMsgShow("黑球进球，没确定花色，我方失败");
                                                webNetworkMananger.getInstance().sendWinUserId(GameData.rivalUserData.userId);
                                            } else {
                                                if (this.seeAboutSurplus(this.myColor, this.ballArr)) {//自己的球还没打完
                                                    this.shootBallMsgShow("黑球进球，我方花色球没打完，我方失败");
                                                    webNetworkMananger.getInstance().sendWinUserId(GameData.rivalUserData.userId);
                                                    //我方失败
                                                } else {//自己的球打光了

                                                    //2019年1月16日 17:06:28  by 雾里有江馆
                                                    if (this.baiBallIntoNow) {
                                                        this.shootBallMsgShow("黑球进球，我方花色球打完，白球进洞,我方失败");
                                                        //我方失败
                                                        webNetworkMananger.getInstance().sendWinUserId(GameData.rivalUserData.userId);

                                                    } else {
                                                        this.shootBallMsgShow("黑球进球，我方花色球打完，白球没进,我方胜利");
                                                        //我方胜利
                                                        webNetworkMananger.getInstance().sendWinUserId(GameData.myUserData.userId);
                                                    }

                                                }
                                            }


                                        }
                                    } else {//黑球没进洞
                                        if (this.baiBallIntoNow) {//白球进了
                                            if (this.myColor == -1) {//没确定花色
                                                if (this.isFirstLeg) {//首杆进白球，对方自由球
                                                    this.shootBallMsgShow("进球了，白球进了，首杆，对方线后自由球");
                                                    webNetworkMananger.getInstance().SendShootEndMeesage(1, GameData.rivalUserData.userId);
                                                } else {//不是首杆
                                                    //进了一个球以上
                                                    if (!this.seeAboutIsConfirmColor(this.firstCollision)) {//无法确定花色，对方自由球
                                                        this.shootBallMsgShow("进球了，白球进了，碰到和进的不是是同花色，无法确定花色为，对方自由球");
                                                        webNetworkMananger.getInstance().SendShootEndMeesage(2, GameData.rivalUserData.userId);
                                                    } else {//可以确认花色，对方自由球
                                                        let ball = this.seeAboutIsConfirmColor(this.firstCollision);
                                                        if (this.seeAboutBallColor(ball) == 0) {//实心
                                                            this.shootBallMsgShow("进球了，白球进了，碰到和进的是同花色，可以确定花色为花色，对方自由球");
                                                            webNetworkMananger.getInstance().SendShootEndMeesage(2, GameData.rivalUserData.userId);
                                                            webNetworkMananger.getInstance().confirmColor(GameData.myUserData.userId, GameData.rivalUserData.userId);

                                                        } else {//花色
                                                            this.shootBallMsgShow("进球了，白球进了，碰到和进的是同花色，可以确定花色为花色，对方自由球");
                                                            webNetworkMananger.getInstance().SendShootEndMeesage(2, GameData.rivalUserData.userId);
                                                            webNetworkMananger.getInstance().confirmColor(GameData.rivalUserData.userId, GameData.myUserData.userId);

                                                        }
                                                        //已上移
                                                        // webNetworkMananger.getInstance().SendShootEndMeesage(2, GameData.rivalUserData.userId);
                                                    }
                                                }
                                            } else {//花色确定，对方自由球
                                                this.shootBallMsgShow("进球了，白球进了，自己花色确定，对方自由球");
                                                webNetworkMananger.getInstance().SendShootEndMeesage(2, GameData.rivalUserData.userId);
                                            }
                                        } else {//白球没进
                                            //碰到第一个球是黑球
                                            if (this.seeAboutBallColor(this.firstCollision) == 2) {
                                                if (this.myColor != -1) {
                                                    if (this.seeAboutSurplus(this.myColor, this.ballArr)) {
                                                        this.shootBallMsgShow("黑球没进，白球没进，碰到黑球，我方花色还有剩余，对方自由球");
                                                        webNetworkMananger.getInstance().SendShootEndMeesage(2, GameData.rivalUserData.userId);
                                                    } else {
                                                        this.shootBallMsgShow("黑球没进，白球没进，碰到黑球，我方花色没有剩余，对方击球球");
                                                        webNetworkMananger.getInstance().SendShootEndMeesage(3, GameData.rivalUserData.userId);
                                                    }
                                                } else {//花色不确定
                                                    if (this.removeBallArr.length > 0) {//如果进球了
                                                        if (this.seeAboutBallColor(this.removeBallArr[0]) == 0) {//确定花色为实心
                                                            this.shootBallMsgShow("黑球没进，白球没进，碰到黑球，进球，确定花色为实心，连杆");
                                                            //连杆
                                                            webNetworkMananger.getInstance().SendShootEndMeesage(3, GameData.myUserData.userId);
                                                            webNetworkMananger.getInstance().confirmColor(GameData.myUserData.userId, GameData.rivalUserData.userId);

                                                        } else {//花心
                                                            this.shootBallMsgShow("黑球没进，白球没进，碰到黑球，进球，确定花色为花色，连杆");
                                                            //连杆
                                                            webNetworkMananger.getInstance().SendShootEndMeesage(3, GameData.myUserData.userId);
                                                            webNetworkMananger.getInstance().confirmColor(GameData.rivalUserData.userId, GameData.myUserData.userId);

                                                        }
                                                        /**以下内容已上移 */
                                                        // //连杆
                                                        // webNetworkMananger.getInstance().SendShootEndMeesage(3, GameData.myUserData.userId);
                                                    } else {
                                                        this.shootBallMsgShow("黑球没进，白球没进，碰到黑球，我方花色没确定花色，对方击球");
                                                        webNetworkMananger.getInstance().SendShootEndMeesage(3, GameData.rivalUserData.userId);
                                                    }
                                                }

                                            } else {
                                                if (this.myColor == -1) {//没确定花色
                                                    if (this.isFirstLeg) {//如果是首杆进球了
                                                        this.shootBallMsgShow("首杆，不确定花色，连杆");
                                                        webNetworkMananger.getInstance().SendShootEndMeesage(3, GameData.myUserData.userId);
                                                    } else {
                                                        if (!this.seeAboutIsConfirmColor(this.firstCollision)) {//无法确认球的花色，正常交换球权


                                                            //2019.01.14修改 by 雾里有江馆
                                                            // this.shootBallMsgShow("进球了，白球没进，自己花色没确定，碰到和进的不是同花色，确定花色为进的球的花色,连杆");
                                                            // webNetworkMananger.getInstance().SendShootEndMeesage(3, GameData.myUserData.userId);



                                                            let ball = this.seeAboutIsConfirmColor(this.firstCollision);
                                                            if (this.seeAboutBallColor(ball) == 1) {//花色
                                                                this.shootBallMsgShow("进球了，白球没进，不确定花色，碰到花色进实心，不确定花色为实心球，连杆");
                                                                webNetworkMananger.getInstance().SendShootEndMeesage(3, GameData.myUserData.userId);
                                                                // webNetworkMananger.getInstance().confirmColor(GameData.myUserData.userId, GameData.rivalUserData.userId);


                                                            } else {//全色
                                                                this.shootBallMsgShow("进球了，白球没进，不确定花色，碰到实心进花心，不确定花色为花球，连杆");
                                                                webNetworkMananger.getInstance().SendShootEndMeesage(3, GameData.myUserData.userId);
                                                                // webNetworkMananger.getInstance().confirmColor(GameData.rivalUserData.userId, GameData.myUserData.userId);


                                                            }


                                                            // this.shootBallMsgShow("进球了，白球没进，自己花色没确定，碰到和进的不是同花色，对方击球");//原版
                                                            // webNetworkMananger.getInstance().SendShootEndMeesage(3, GameData.rivalUserData.userId);
                                                        } else {//可以确认花色，连杆
                                                            let ball = this.seeAboutIsConfirmColor(this.firstCollision);
                                                            if (this.seeAboutBallColor(ball) == 0) {//实心
                                                                this.shootBallMsgShow("进球了，白球没进，自己花色确定，碰到和进的是同花色，确定花色为实心球，连杆");
                                                                webNetworkMananger.getInstance().SendShootEndMeesage(3, GameData.myUserData.userId);
                                                                webNetworkMananger.getInstance().confirmColor(GameData.myUserData.userId, GameData.rivalUserData.userId);


                                                            } else {//花色
                                                                this.shootBallMsgShow("进球了，白球没进，自己花色确定，碰到和进的是同花色，确定花色为花球，连杆");
                                                                webNetworkMananger.getInstance().SendShootEndMeesage(3, GameData.myUserData.userId);
                                                                webNetworkMananger.getInstance().confirmColor(GameData.rivalUserData.userId, GameData.myUserData.userId);


                                                            }
                                                            /**已上移 */
                                                            // webNetworkMananger.getInstance().SendShootEndMeesage(3, GameData.myUserData.userId);
                                                        }
                                                    }
                                                } else {//确定花色
                                                    if (this.seeAboutBallColor(this.firstCollision) == this.myColor) {//如果碰到的第一个球是自己的花色
                                                        if (!this.seeAboutIsConfirmColor(this.firstCollision)) {//如果自己花色球没进，正常交换球权
                                                            this.shootBallMsgShow("进球了，白球没进，自己花色确定，碰到自己花色球，但是没进，对方击球");
                                                            webNetworkMananger.getInstance().SendShootEndMeesage(3, GameData.rivalUserData.userId);
                                                        } else {//如果进了，连杆
                                                            this.shootBallMsgShow("进球了，白球没进，自己花色确定，碰到自己花色球，进球，连杆");
                                                            webNetworkMananger.getInstance().SendShootEndMeesage(3, GameData.myUserData.userId);
                                                        }
                                                    } else {//碰到第一个球不是自己的花色，对方自由球
                                                        this.shootBallMsgShow("进球了，白球没进，自己花色确定，碰到别人花色球，对方自由球");
                                                        webNetworkMananger.getInstance().SendShootEndMeesage(2, GameData.rivalUserData.userId);
                                                    }
                                                }
                                            }

                                        }
                                    }
                                } else {//没有进球
                                    //碰到第一个球是黑球
                                    if (this.seeAboutBallColor(this.firstCollision) == 2) {//0-实心球 1-花心球 2-黑球
                                        if (this.myColor != -1) {//花色确定
                                            if (this.seeAboutSurplus(this.myColor, this.ballArr)) {
                                                this.shootBallMsgShow("黑球没进，白球没进，碰到黑球，我方花色还有剩余，对方自由球");
                                                webNetworkMananger.getInstance().SendShootEndMeesage(2, GameData.rivalUserData.userId);
                                            } else {
                                                this.shootBallMsgShow("黑球没进，白球没进，碰到黑球，我方花色没有剩余，对方击球球");
                                                webNetworkMananger.getInstance().SendShootEndMeesage(3, GameData.rivalUserData.userId);
                                            }
                                        } else {//花色不确定
                                            this.shootBallMsgShow("黑球没进，白球没进，碰到黑球，我方花色没确定花色，对方击球");
                                            webNetworkMananger.getInstance().SendShootEndMeesage(3, GameData.rivalUserData.userId);
                                        }
                                    } else {
                                        if (this.myColor == -1) {//花色没确定,正常交换球权
                                            webNetworkMananger.getInstance().SendShootEndMeesage(3, GameData.rivalUserData.userId);
                                            this.shootBallMsgShow("没有进球，自己花色没确定，对方击球");
                                        } else {//花色确定
                                            if (this.seeAboutIsMyColor(this.myColor, this.firstCollision)) {//碰到自己花色的球，正常交换球权
                                                this.shootBallMsgShow("没有进球，自己花色确定，碰到自己花色球，对方击球");
                                                webNetworkMananger.getInstance().SendShootEndMeesage(3, GameData.rivalUserData.userId);
                                            } else {//碰到对方花色球，对方自由球
                                                this.shootBallMsgShow("没有进球，自己花色确定，碰到别人花色球，对方自由球");
                                                webNetworkMananger.getInstance().SendShootEndMeesage(2, GameData.rivalUserData.userId);
                                            }
                                        }
                                    }
                                }
                            } else {


                                //本回合没有碰到任何彩球
                                if (this.isFirstLeg) {//首杆都是线后自由球 对方摆球
                                    if (this.baiBallIntoNow) {
                                        this.shootBallMsgShow("首杆, 没有碰到彩球, 白球进，对方线后自由球");
                                        webNetworkMananger.getInstance().SendShootEndMeesage(1, GameData.rivalUserData.userId);
                                    } else {
                                        this.shootBallMsgShow("首杆, 没有碰到彩球, 对方线后自由球");
                                        webNetworkMananger.getInstance().SendShootEndMeesage(1, GameData.rivalUserData.userId);
                                    }

                                }
                                else {
                                    if (this.baiBallIntoNow) {
                                        this.shootBallMsgShow("没有碰到彩球, 白球进，对方自由球");
                                        webNetworkMananger.getInstance().SendShootEndMeesage(2, GameData.rivalUserData.userId);
                                    } else {
                                        this.shootBallMsgShow("没有碰到彩球, 白球进，对方自由球");
                                        webNetworkMananger.getInstance().SendShootEndMeesage(2, GameData.rivalUserData.userId);
                                    }
                                }




                            }
                        }
                    } else {//AI判定  
                        if (this.firstCollision != 0) {//本回合碰到球
                            if (this.iiiNow > 0) {//进球了
                                if (this.blackBallIntoNow) {//黑球进洞
                                    if (this.isFirstLeg) {//首杆黑8进球
                                        this.shootBallMsgShow("首杆黑8进球，对方线后自由球");
                                        this.homeServer.exchangeBall(false, 1);
                                    } else {//首杆黑8未进球
                                        if (this.homeServer.getNowLegShootColor() == -1) {//没确定花色
                                            this.shootBallMsgShow("黑球进球，没确定花色，失败");
                                            this.homeServer.determineOutcome(false);
                                            //webNetworkMananger.getInstance().sendWinUserId(GameData.rivalUserData.userId);
                                        } else {
                                            if (this.seeAboutSurplus(this.homeServer.getNowLegShootColor(), this.ballArr)) {//自己的球还没打完
                                                this.shootBallMsgShow("黑球进球，花色球没打完，失败");
                                                this.homeServer.determineOutcome(false);
                                                //webNetworkMananger.getInstance().sendWinUserId(GameData.rivalUserData.userId);
                                            } else {//自己的球打光了
                                                this.shootBallMsgShow("黑球进球，花色球打完，胜利");
                                                this.homeServer.determineOutcome(true);
                                                //webNetworkMananger.getInstance().sendWinUserId(GameData.myUserData.userId);
                                            }
                                        }
                                    }
                                } else {//黑球没进洞
                                    if (this.baiBallIntoNow) {//白球进了
                                        if (this.homeServer.getNowLegShootColor() == -1) {//没确定花色
                                            if (this.isFirstLeg) {//首杆进白球，对方自由球
                                                this.shootBallMsgShow("进球了，白球进了，首杆，对方线后自由球");
                                                this.homeServer.exchangeBall(false, 1);

                                            } else {//不是首杆
                                                let result = this.seeAboutIsConfirmColor(this.firstCollision);
                                                if (result == false) {//无法确定花色，对方自由球
                                                    this.shootBallMsgShow("进球了，白球进了，碰到和进的不是是同花色，无法确定花色为，对方自由球");
                                                    this.homeServer.exchangeBall(false, 2);

                                                } else {//可以确认花色，对方自由球
                                                    if (this.seeAboutBallColor(result) == 0) {//实心
                                                        this.shootBallMsgShow("进球了，白球进了，碰到和进的是同花色，可以确定花色为花色，对方自由球");
                                                        this.homeServer.exchangeBall(false, 2);
                                                        this.homeServer.confirmColor(0);

                                                    } else {//花色
                                                        this.shootBallMsgShow("进球了，白球进了，碰到和进的是同花色，可以确定花色为花色，对方自由球");
                                                        this.homeServer.exchangeBall(false, 2);
                                                        this.homeServer.confirmColor(1);
                                                    }
                                                }

                                            }
                                        } else {//花色确定，对方自由球
                                            this.shootBallMsgShow("进球了，白球进了，自己花色确定，对方自由球");
                                            this.homeServer.exchangeBall(false, 2);

                                        }
                                    } else {//白球没进
                                        //碰到第一个球是黑球
                                        if (this.seeAboutBallColor(this.firstCollision) == 2) {//0-实心球 1-花心球 2-黑球
                                            if (this.myColor != -1) {//花色确定
                                                if (this.seeAboutSurplus(this.homeServer.getNowLegShootColor(), this.ballArr)) {
                                                    this.shootBallMsgShow("黑球没进，白球没进，碰到黑球，我方花色还有剩余，对方自由球");
                                                    this.homeServer.exchangeBall(false, 2);
                                                } else {
                                                    this.shootBallMsgShow("黑球没进，白球没进，碰到黑球，我方花色没有剩余，对方击球球");
                                                    this.homeServer.exchangeBall(false, 3);
                                                }
                                            } else {//花色不确定
                                                if (this.removeBallArr.length > 0) {//如果进球了
                                                    if (this.seeAboutBallColor(this.removeBallArr[0]) == 0) {//确定花色为实心
                                                        this.shootBallMsgShow("黑球没进，白球没进，碰到黑球，进球，确定花色为实心，连杆");
                                                        this.homeServer.exchangeBall(true, 3);

                                                        this.homeServer.confirmColor(0);
                                                    } else {//花心
                                                        this.shootBallMsgShow("黑球没进，白球没进，碰到黑球，进球，确定花色为花色，连杆");
                                                        this.homeServer.exchangeBall(true, 3);

                                                        this.homeServer.confirmColor(1);
                                                    }
                                                    //连杆
                                                    // this.homeServer.exchangeBall(true, 3);

                                                } else {
                                                    this.shootBallMsgShow("黑球没进，白球没进，碰到黑球，我方花色没确定花色，对方击球");
                                                    this.homeServer.exchangeBall(false, 3);
                                                }
                                            }
                                        } else {
                                            if (this.homeServer.getNowLegShootColor() == -1) {//没确定花色
                                                if (this.isFirstLeg) {
                                                    this.shootBallMsgShow("首杆，不确定花色，连杆");
                                                    this.homeServer.exchangeBall(true, 3);

                                                } else {
                                                    let result = this.seeAboutIsConfirmColor(this.firstCollision);
                                                    if (result == false) {//无法确认球的花色，正常交换球权
                                                        this.shootBallMsgShow("进球了，白球没进，自己花色没确定，碰到和进的不是同花色，对方击球");
                                                        this.homeServer.exchangeBall(false, 3);

                                                    } else {//可以确认花色，连杆
                                                        if (this.seeAboutBallColor(result) == 0) {//实心
                                                            this.shootBallMsgShow("进球了，白球没进，自己花色确定，碰到和进的是同花色，确定花色为实心球，连杆");

                                                            this.homeServer.exchangeBall(true, 3);

                                                            this.homeServer.confirmColor(0);

                                                        } else {//花色
                                                            this.shootBallMsgShow("进球了，白球没进，自己花色确定，碰到和进的是同花色，确定花色为花球，连杆");
                                                            this.homeServer.exchangeBall(true, 3);

                                                            this.homeServer.confirmColor(1);

                                                        }
                                                        //已上移
                                                        // this.homeServer.exchangeBall(true, 3);
                                                    }
                                                }
                                            } else {//确定花色
                                                if (this.seeAboutBallColor(this.firstCollision) == this.homeServer.getNowLegShootColor()) {//如果碰到的第一个球是自己的花色
                                                    if (!this.seeAboutIsConfirmColor(this.firstCollision)) {//如果自己花色球没进，正常交换球权
                                                        this.shootBallMsgShow("进球了，白球没进，自己花色确定，碰到自己花色球，但是没进，对方击球");
                                                        this.homeServer.exchangeBall(false, 3);

                                                    } else {//如果进了，连杆
                                                        this.shootBallMsgShow("进球了，白球没进，自己花色确定，碰到自己花色球，进球，连杆");
                                                        this.homeServer.exchangeBall(true, 3);

                                                    }
                                                } else {//碰到第一个球不是自己的花色，对方自由球
                                                    this.shootBallMsgShow("进球了，白球没进，自己花色确定，碰到别人花色球，对方自由球");
                                                    this.homeServer.exchangeBall(false, 2);

                                                }
                                            }
                                        }
                                    }
                                }
                            } else {//没有进球
                                //碰到第一个球是黑球
                                if (this.seeAboutBallColor(this.firstCollision) == 2) {//0-实心球 1-花心球 2-黑球
                                    if (this.myColor != -1) {//花色确定
                                        if (this.seeAboutSurplus(this.homeServer.getNowLegShootColor(), this.ballArr)) {
                                            this.shootBallMsgShow("黑球没进，白球没进，碰到黑球，我方花色还有剩余，对方自由球");
                                            this.homeServer.exchangeBall(false, 2);
                                        } else {
                                            this.shootBallMsgShow("黑球没进，白球没进，碰到黑球，我方花色没有剩余，对方击球球");
                                            this.homeServer.exchangeBall(false, 3);
                                        }
                                    } else {//花色不确定
                                        this.shootBallMsgShow("黑球没进，白球没进，碰到黑球，我方花色没确定花色，对方击球");
                                        this.homeServer.exchangeBall(false, 3);
                                    }
                                } else {
                                    if (this.homeServer.getNowLegShootColor() == -1) {//花色没确定，对方自由球
                                        this.shootBallMsgShow("没有进球，自己花色没确定，对方击球");
                                        this.homeServer.exchangeBall(false, 3);

                                    } else {//花色确定
                                        if (this.seeAboutIsMyColor(this.homeServer.getNowLegShootColor(), this.firstCollision)) {//碰到自己花色的球，正常交换球权
                                            this.shootBallMsgShow("没有进球，自己花色确定，碰到自己花色球，对方击球");
                                            this.homeServer.exchangeBall(false, 3);

                                        } else {//碰到对方花色球，对方自由球
                                            this.shootBallMsgShow("没有进球，自己花色确定，碰到别人花色球，对方自由球");

                                            this.homeServer.exchangeBall(false, 2);
                                        }
                                    }
                                }

                            }
                        } else {




                            //本回合没有碰到任何彩球，对方自由球
                            if (this.isFirstLeg) {//首杆 对方线后自由球
                                if (this.baiBallIntoNow) {
                                    this.shootBallMsgShow("首杆, 没有碰到彩球，白球进洞, 对方线后自由球");
                                    this.homeServer.exchangeBall(false, 1);
                                } else {
                                    this.shootBallMsgShow("首杆, 没有碰到彩球，对方线后自由球");
                                    this.homeServer.exchangeBall(false, 1);
                                }
                            } else {//非首杆 对方自由球
                                if (this.baiBallIntoNow) {
                                    this.shootBallMsgShow("本回合没有碰到彩球，对方自由球");
                                    this.homeServer.exchangeBall(false, 2);
                                } else {
                                    this.shootBallMsgShow("没有碰到彩球，白球进洞, 对方自由球");
                                    this.homeServer.exchangeBall(false, 2)
                                }
                            }







                        }
                    }


                    /**真人对战回合结束 */
                    if (webNetworkMananger.getInstance().isMoving) {
                        webNetworkMananger.getInstance().isCanSync = true;
                        // egret.setTimeout(e => {
                        //     this.myLeg = webNetworkMananger.getInstance().isMyLeg;
                        //     webNetworkMananger.getInstance().dealWithBallSync();
                        //     //判断回合是否交换
                        //     if (this.myLeg) {
                        //         this.changeType(webNetworkMananger.getInstance().hitBallType);
                        //         console.log("我的回合");
                        //         this.LighttoMyBalls();
                        //         if (this.lastshoot != GameData.myAccount) {
                        //             // } else {
                        //             this.nowCombox = 0;
                        //             console.log("changed ! ! !")
                        //         }
                        //         this.lastshoot = GameData.myAccount;
                        //         TableUI.Instance().ld.visible = true;
                        //         TableUI.Instance().slipgroup.visible = true;
                        //         TableUI.Instance().MyRange.touchEnabled = true;
                        //     } else {
                        //         TableUI.Instance().ld.visible = false;
                        //         TableUI.Instance().slipgroup.visible = false;
                        //         TableUI.Instance().MyRange.touchEnabled = false;
                        //         console.log("对方的回合");
                        //         if (this.lastshoot != GameData.rivalUserData) {
                        //             // } else {
                        //             this.nowCombox = 0;
                        //             console.log("changed ! ! !")
                        //         }
                        //         this.lastshoot = GameData.rivalUserData;
                        //     }
                        // }, this, 1000);

                    }
                    else {//人机对战
                        this.setSour(this.sour);//处理提示消息先后顺序
                        if (this.lastshoot != this.homeServer.getNowLegShootColor()) {

                            // } else {
                            this.nowCombox = 0;
                            console.log("Changed ! ! !");
                        }
                        this.lastshoot = this.homeServer.getNowLegShootColor();
                    }

                    this.isComBoOK = false; this.iiiNow = 0;
                    this.iii = 0;
                    this.baiBallIntoNow = false;
                    this.blackBallIntoNow = false;
                    /**第一个碰的球 */
                    this.firstCollision = 0;
                    /**进的球 */
                    this.removeBallArr = [];
                    this.isFirstLeg = false;

                }
                else if (this.isLianxi == 2) {
                    let surplusNum = 0;
                    this.nowCombox == 0;
                    for (let i = 0; i < this.ballArr.length; i++) {
                        if (this.ballArr[i].isJindong != -2) {
                            surplusNum++;
                        }
                    }
                    if (surplusNum == 1) {
                        var winUI: WinUI = new WinUI();
                        console.log("solo win");
                        winUI.x = this.centerX - 546 / 2;
                        winUI.y = this.centerY - 469 / 2;

                        this.addChild(winUI);
                        winUI.playAction();
                    }
                    else {
                        this.isOwnGame = true;
                    }

                    if (this.curBall.nextX == -17 && this.curBall.nextY == -17) {
                        this.isBaiqiu = 2;
                    }
                }

                this.isMove = false;


                //this.showGan(1000, 100);

                break;
            }
        }

        var len: number = this.ballArr.length;
        for (var i: number = len - 1; i >= 0; i--) {
            var b: NewBall = this.ballArr[i];
            if (b.isJindong == -2) {
                continue;
            }
            setBallPos(b.nextX, b.nextY, b.lastX, b.lastY, i);
            b.lastX = b.nextX;
            b.lastY = b.nextY;
        }
    }
    /**击球判定显示 */
    public shootBallMsgShow(msg) {
        this.shootBallShow.visible = false;
        this.shootBallShow.text = "击球判定：" + msg;
    }
    /**判断胜负 */
    public judgeSuccessFailure(isWin: boolean) {
        if (this.homeServer && this.homeServer.AI) {
            this.homeServer.AI.restAI();//停下AI
        }
        this.ld.visible = false;
        this.slipgroup.visible = false;
        this.MyRange.touchEnabled = false;//禁止玩家操作
        this.removeAllEventListener();//禁止玩家操作
        this.ClearW();
        this.ClearAllLine();
        this.HideGanImg();
        //this.restData();
        this.setSour("");//停用提示文字
        if (isWin) {
            var winUI: WinUI = new WinUI();
            winUI.x = this.centerX - 546 / 2;
            winUI.y = this.centerY - 469 / 2;

            this.addChild(winUI);
            winUI.playAction();
        } else {
            var loseUI: LoseUI = new LoseUI();
            loseUI.x = this.centerX - 546 / 2;
            loseUI.y = this.centerY - 469 / 2;

            this.addChild(loseUI);
            loseUI.playAction();
        }
    }
    /**查询此花色还有没有剩余
     * 0-实心球
     * 1-花球
     */
    public seeAboutSurplus(color: number, ballArr) {
        ballArr = this.ballArr;
        for (let i = 0; i < ballArr.length; i++) {
            if (ballArr[i].isJindong == -2) {
                continue;
            }
            if (color == 0) {
                if (ballArr[i].idx > 0 && ballArr[i].idx < 8) {
                    return true;
                }
            } else {
                if (ballArr[i].idx > 8) {
                    return true;
                }
            }
        }
        //显示黑八
        if (color == 0) {
            this.ShowBall8();
        } else {
            this.ShowBall16();
        }
        return false;
    }
    /**判断是否是自己的花色 */
    private seeAboutIsMyColor(myColor, ballidx) {
        if (myColor != -1) {
            if (myColor == 0) {//实心球
                if (ballidx > 0 && ballidx < 8) {
                    return true;
                } else {
                    return false;
                }
            } else {//空心球
                if (ballidx > 8) {
                    return true;
                } else {
                    return false;
                }
            }
        }
    }
    /**判断两个球花色是否一样 */
    private seeAboutTwoBallIsSame(ball1, ball2) {
        ball1 -= 7;
        ball2 -= 7;
        if (ball1 <= 0 && ball2 <= 0) {//实心球
            return true;
        } else if (ball1 >= 2 && ball2 >= 2) {//花心球
            return true;
        } else {
            return false;
        }
    }
    /**判断球的花色 */
    public seeAboutBallColor(ballNum) {//0-实心球 1-花心球 2-黑球  -10 白球
        if (ballNum > 0 && ballNum < 8) {
            return 0;
        } else if (ballNum > 8) {
            return 1;
        } else if (ballNum == 8) {
            return 2;
        }
        else if (ballNum == 0) {
            return -10;
        }
    }
    /**判断第一个碰到的球和进的球是否是同花色 */
    private seeAboutIsConfirmColor(firstCollision) {
        let firstColor = this.seeAboutBallColor(firstCollision);
        for (let i = 0; i < this.removeBallArr.length; i++) {
            if (this.seeAboutBallColor(this.removeBallArr[i]) == firstColor) {
                return this.removeBallArr[i];
            }
        }
        return false;
    }

    private jinqiuAction(num: number) {

        // /**测试区域 */
        // var rtx: eui.Image = new eui.Image("mask_png");
        // rtx.anchorOffsetX = 250;
        // rtx.anchorOffsetY = 250;
        // rtx.width = 500;
        // rtx.height = 500;
        // rtx.name = "测试用遮罩";
        // rtx.alpha = 0.5;
        // rtx.touchEnabled = false;
        // this.addChild(rtx);
        // this.swapChildren(rtx, armature.display);

        // var dragonbonesData = RES.getRes("jinqiu3");
        // var textureData = RES.getRes("jinqiu2");
        // var texture = RES.getRes("jinqiu1");

        var dragonbonesData = RES.getRes("liangan3_json");
        var textureData = RES.getRes("liangan2_json");
        var texture = RES.getRes("liangan1_png");//资源名字
        // var dragonbonesData = RES.getRes("liangan3");
        // var textureData = RES.getRes("liangan2");
        // var texture = RES.getRes("liangan1");
        var dragonbonesFactory: dragonBones.EgretFactory = new dragonBones.EgretFactory();
        dragonbonesFactory.addDragonBonesData(dragonBones.DataParser.parseDragonBonesData(dragonbonesData));
        dragonbonesFactory.addTextureAtlas(new dragonBones.EgretTextureAtlas(texture, textureData));
        var armature: dragonBones.Armature = dragonbonesFactory.buildArmature("Armature");
        this.addChild(armature.display);
        armature.display.x = this.posArr[num].hx;
        armature.display.y = this.posArr[num].hy;
        dragonBones.WorldClock.clock.add(armature);

        // rtx.x = armature.display.x;
        // rtx.y = armature.display.y;
        armature.addEventListener(egret.Event.COMPLETE, function () {
            dragonBones.WorldClock.clock.remove(armature);
            if (armature.display.parent) {
                this.removeChild(armature.display);
                // this.removeChild(rtx)
            }
        }.bind(this), this);
        // armature.animation.gotoAndPlay("01", -1, -1, 1);
        armature.animation.play("jinqiu", 1);

    }
    //进球头像特效 
    /** 进球头像特效  0-我方，1-对面*/
    public lightning(num: number) {// stop: boolean
        if (num != 1 && num != 0) {
            return;
        }
        var dragonbonesData = RES.getRes("liangan3_json");
        var textureData = RES.getRes("liangan2_json");
        var texture = RES.getRes("liangan1_png");//资源名字
        var dragonbonesFactory: dragonBones.EgretFactory = new dragonBones.EgretFactory();
        dragonbonesFactory.addDragonBonesData(dragonBones.DataParser.parseDragonBonesData(dragonbonesData));
        dragonbonesFactory.addTextureAtlas(new dragonBones.EgretTextureAtlas(texture, textureData));
        var armature: dragonBones.Armature = dragonbonesFactory.buildArmature("Armature");
        this.addChild(armature.display);
        armature.display.x = this.photos[num].x;
        armature.display.y = this.photos[num].y;
        dragonBones.WorldClock.clock.add(armature);

        armature.addEventListener(egret.Event.COMPLETE, function () {
            dragonBones.WorldClock.clock.remove(armature);
            if (armature.display.parent) {
                this.removeChild(armature.display);
            }

        }.bind(this), this);
        armature.animation.play("touxiang", 1);
    }



    /**
     * 进球滚动
     */
    private gomoveccc(idx: number) {
        var ball: NewBall = this.ballArr[idx];
        ball.nextX = 1142;
        ball.nextY = 172;
        if (ball.nextY < 666) {
            ball.vy = 1;
        } else {
            ball.vy = 0;
        }
        // ball.vx = 5;
    }


    public hole: number = 0;


    /** 检查6个洞及墙的碰撞 */
    private checkWalls(b: NewBall) {
        for (var i: number = 0; i < 6; i++) {
            var _hx: number = this.posArr[i].hx;
            var _hy: number = this.posArr[i].hy;
            if (b.nextX > _hx - this.holeR && b.nextX < _hx + this.holeR && b.nextY > _hy - this.holeR && b.nextY < _hy + this.holeR) {
                var dx: number = b.nextX - _hx;
                var dy: number = b.nextY - _hy;
                var dist: number = Math.sqrt(dx * dx + dy * dy);
                if (dist < this.holeR) {
                    console.log("进球号： " + b.idx);
                    this.showBall(b.idx);
                    this.seeAboutSurplus(this.seeAboutBallColor(b.idx), this.ballArr);
                    if (this.isFirstLeg) {
                        if (b.idx == 8) {
                            console.log("首杆黑8");
                            b.name = "black";
                        }
                    } else {
                        if (b.idx == 8) {
                            b.name = "";
                        }
                    }
                    if (b.idx == 0) {//进了白球
                        if (this.isLianxi == 1) {// && (webNetworkMananger.getInstance().isMove
                            // if (this.myLeg) {
                            //     this.setSourofPromptword('word4');   //母球落袋 对方获得自由球
                            // } else {
                            //     this.setSourofPromptword('word5');   //母球落袋 你获得自由球
                            // }

                            // if (GameData.isStandalone && this.homeServer.nowShoot == -1) {//AI我的回合  //AI 单机 true
                            //     this.setSourofPromptword('word4');
                            // } else {
                            //     this.setSourofPromptword('word5');
                            // }
                        }
                        else {
                            this.setSour('word15');
                        }
                    }
                    else {

                        //combox动画
                        if (this.seeAboutBallColor(b.idx) == this.getnowshootcolor()
                            || (this.getnowshootcolor() == -1)) //未确定花色也算combo
                        {

                            this.nowCombox++;
                            this.ShowComBo(i, this.nowCombox);
                        }


                    }
                    console.log("本回合进球数：", ++this.iiiNow);
                    //玩家进球头像闪烁 已改倒计时闪烁  勿删
                    // if (b.idx != 0) {
                    //     if (this.myColor != -1) {
                    //         if (webNetworkMananger.getInstance().isMoving && this.isLianxi == 1) {
                    //             if (this.myLeg) {
                    //                 this.lightning(0);//头像特效
                    //             } else if (!this.myLeg) {
                    //                 this.lightning(1);
                    //             }
                    //         }
                    //         if (!webNetworkMananger.getInstance().isMoving && this.isLianxi == 1) {
                    //             if (this.homeServer.nowShoot == -1) {
                    //                 this.lightning(0);//头像特效
                    //             } else if (this.homeServer.nowShoot == 1) {
                    //                 this.lightning(1);
                    //             }
                    //         }
                    //     }
                    // }
                    this.intoBallNow.push(b);
                    if (b.idx != 0) {
                        this.hole = i;
                        this.scoreiii += 100; //进彩球得分 
                        if (this.isLianxi == 2) {
                            console.log(this.iii % 8);
                            this.ShowComBo(i, this.iii % 8);//击球特效
                        }
                        if (b.idx == 8) {
                            this.blackBallIntoNow = true;
                        }
                    } else {
                        this.scoreiii -= 50;  //进白球减分
                        this.baiBallIntoNow = true;
                    }
                    // this.scoretext.text = "" + this.scoreiii;//实时更新
                    // var channel: egret.SoundChannel = this.soundrudong.play(0, 1);
                    var v = Math.sqrt(b.vx * b.vx + b.vy * b.vy) / 2;
                    this.PlaySoundWithVolume(v, TableUI.Instance().goalSound);
                    // if (v > 1) v = 1;
                    // //channel.volume = v;

                    b.vx = 0;
                    b.vy = 0;
                    b.isJindong = i;
                    // this.gomoveccc(b.idx);
                }
            }
        }
        //左边底线直线
        var angle: number = 0;
        if (this.EdgeTesting(b.nextX, b.nextY) == 4 || this.HypotenuseDown0(b.nextX, b.nextY) == 1 || this.HypotenuseUp3(b.nextX, b.nextY) == 1) {//
            b.nextX = this.posArr[0].x3 + this._r;
            //var channel: egret.SoundChannel = this.soundzhuangbian.play(0, 1);

            var v = Math.sqrt(b.vx * b.vx + b.vy * b.vy) / 2;
            if (v > 1) v = 1;
            //channel.volume = v;
            // console.log("first", b.vx)
            b.vx *= this.bounce
            //    console.log("second", b.vx)
            return false;
        }
        if (this.HypotenuseDown0(b.nextX, b.nextY) == 2) {
            //  b.nextX = this.posArr[0].x3 + this._r;
            // console.log("222222");

            //var channel: egret.SoundChannel = this.soundzhuangbian.play(0, 1);
            var v = Math.sqrt(b.vx * b.vx + b.vy * b.vy) / 2;
            if (v > 1) v = 1;
            //channel.volume = v;
            // channel.volume = Math.sqrt(b.vx * b.vx + b.vy * b.vy) / 2;
            angle = this.GetAngle(this.trapezoid_H, this.trapezoid_Long);
            if (b.vx < 0) {
                //   console.log("111111")
                b.vx = 0;
                b.vy = -1;
            }

            return false;
        }
        if (this.HypotenuseUp3(b.nextX, b.nextY) == 2) {
            // console.log("222222");

            //var channel: egret.SoundChannel = this.soundzhuangbian.play(0, 1);

            var v = Math.sqrt(b.vx * b.vx + b.vy * b.vy) / 2;
            if (v > 1) v = 1;
            //channel.volume = v;
            // channel.volume = Math.sqrt(b.vx * b.vx + b.vy * b.vy) / 2;
            angle = this.GetAngle(this.trapezoid_H, this.trapezoid_Long);

            if (b.vx < 0) {
                // console.log("111111")
                b.vx = 0;
                b.vy = 1;
            }

            return false;
        }
        if (b.nextX < this.posArr[0].x2 + this._r) {

            if (b.nextY <= this.posArr[0].y2) {
                var dx: number = b.nextX - this.posArr[0].x2;
                var dy: number = b.nextY - this.posArr[0].y2;
                var dist: number = Math.sqrt(dx * dx + dy * dy);
                if (dist < this._r) {
                    this.rebound(b, this.posArr[0].x2, this.posArr[0].y2, 0.7);
                }
            }
            if (b.nextY >= this.posArr[3].y1) {
                var dx: number = b.nextX - this.posArr[3].x1;
                var dy: number = b.nextY - this.posArr[3].y1;
                var dist: number = Math.sqrt(dx * dx + dy * dy);
                if (dist < this._r) {
                    this.rebound(b, this.posArr[3].x1, this.posArr[3].y1, 0.7);
                }
            }
        }

        //右边
        if (this.EdgeTesting(b.nextX, b.nextY) == 2 || this.HypotenuseDown2(b.nextX, b.nextY) == 1 || this.HypotenuseUp5(b.nextX, b.nextY) == 1) {
            b.nextX = this.posArr[2].x4 - this._r;
            //var channel: egret.SoundChannel = this.soundzhuangbian.play(0, 1);

            var v = Math.sqrt(b.vx * b.vx + b.vy * b.vy) / 2;
            if (v > 1) v = 1;
            //channel.volume = v;
            // channel.volume = Math.sqrt(b.vx * b.vx + b.vy * b.vy) / 2;
            b.vx *= this.bounce;
        }
        if (this.HypotenuseDown2(b.nextX, b.nextY) == 2) {
            //var channel: egret.SoundChannel = this.soundzhuangbian.play(0, 1);

            var v = Math.sqrt(b.vx * b.vx + b.vy * b.vy) / 2;
            if (v > 1) v = 1;
            //channel.volume = v;
            // channel.volume = Math.sqrt(b.vx * b.vx + b.vy * b.vy) / 2;
            angle = this.GetAngle(this.trapezoid_H, this.trapezoid_Long);
            if (b.vx > 0) {
                //   console.log("111111")
                b.vx = 0;
                b.vy = -1;
            }
            return false;
        }
        if (this.HypotenuseUp5(b.nextX, b.nextY) == 2) {
            //var channel: egret.SoundChannel = this.soundzhuangbian.play(0, 1);

            var v = Math.sqrt(b.vx * b.vx + b.vy * b.vy) / 2;
            if (v > 1) v = 1;
            //channel.volume = v;
            // channel.volume = Math.sqrt(b.vx * b.vx + b.vy * b.vy) / 2;
            angle = this.GetAngle(this.trapezoid_H, this.trapezoid_Long);
            if (b.vx > 0) {
                //   console.log("111111")
                b.vx = 0;
                b.vy = 1;
            }

            return false;
        }
        if (b.nextY <= this.posArr[2].y2) {
            var dx: number = b.nextX - this.posArr[2].x2;
            var dy: number = b.nextY - this.posArr[2].y2;
            var dist: number = Math.sqrt(dx * dx + dy * dy);
            if (dist < this._r) {
                this.rebound(b, this.posArr[2].x2, this.posArr[2].y2, 0.7);
            }
        }
        if (b.nextY >= this.posArr[5].y1) {
            var dx: number = b.nextX - this.posArr[5].x1;
            var dy: number = b.nextY - this.posArr[5].y1;
            var dist: number = Math.sqrt(dx * dx + dy * dy);
            if (dist < this._r) {
                this.rebound(b, this.posArr[5].x1, this.posArr[5].y1, 0.7);
            }
        }
        //上边
        if (this.EdgeTesting(b.nextX, b.nextY) == 1 || this.HypotenuseRight0(b.nextX, b.nextY) == 1 || this.HypotenuseLeft2(b.nextX, b.nextY) == 1) {
            b.nextY = this.posArr[0].y4 + this._r;
            //var channel: egret.SoundChannel = this.soundzhuangbian.play(0, 1);
            //            channel.volume = Math.sqrt(b.vx * b.vx + b.vy * b.vy) / 2;
            var v = Math.sqrt(b.vx * b.vx + b.vy * b.vy) / 2;
            if (v > 1) v = 1;
            //channel.volume = v;
            b.vy *= this.bounce;
        }
        //  console.log("first x y",b.nextX,b.nextY);

        if (this.HypotenuseRight0(b.nextX, b.nextY) == 2) {

            //var channel: egret.SoundChannel = this.soundzhuangbian.play(0, 1);
            var v = Math.sqrt(b.vx * b.vx + b.vy * b.vy) / 2;
            if (v > 1) v = 1;
            //channel.volume = v;
            // channel.volume = Math.sqrt(b.vx * b.vx + b.vy * b.vy) / 2;
            angle = this.GetAngle(this.trapezoid_H, this.trapezoid_Long);
            var vx1 = b.nextX;
            var vy1 = b.nextY;

            if (b.vy < 0) {
                // console.log("222222");
                b.vy = 0;
                b.vx = -1;
                // b.vx-=vy1*this.bounce*Math.sin(angle);
            }
            return false;
        }
        if (this.HypotenuseLeft1(b.nextX, b.nextY) == 1) {
            //var channel: egret.SoundChannel = this.soundzhuangbian.play(0, 1);

            var v = Math.sqrt(b.vx * b.vx + b.vy * b.vy) / 2;
            if (v > 1) v = 1;
            //channel.volume = v;
            // channel.volume = Math.sqrt(b.vx * b.vx + b.vy * b.vy) / 2;
            // angle = this.GetAngle(this.trapezoid_H, this.trapezoid_Middle);
            if (b.vx < 0) {
                b.vx = -0.7 * b.vx;
                b.vy = b.vy * -1.2;
            }
            else {
                console.log("else!")
                b.vy *= this.bounce;
            }
            return false;
        }
        if (this.HypotenuseLeft1(b.nextX, b.nextY) == 2) {
            //var channel: egret.SoundChannel = this.soundzhuangbian.play(0, 1);

            var v = Math.sqrt(b.vx * b.vx + b.vy * b.vy) / 2;
            if (v > 1) v = 1;
            //channel.volume = v;
            // channel.volume = Math.sqrt(b.vx * b.vx + b.vy * b.vy) / 2;
            angle = this.GetAngle(this.trapezoid_H, this.trapezoid_Middle);

            if (b.vy < 0) {
                b.vy = -0.3;
                b.vx = 1;
            }
            return false;
        }
        if (this.HypotenuseRight1(b.nextX, b.nextY) == 1) {

            //var channel: egret.SoundChannel = this.soundzhuangbian.play(0, 1);

            var v = Math.sqrt(b.vx * b.vx + b.vy * b.vy) / 2;
            if (v > 1) v = 1;
            //channel.volume = v;
            // channel.volume = Math.sqrt(b.vx * b.vx + b.vy * b.vy) / 2;
            // angle = this.GetAngle(this.trapezoid_H, this.trapezoid_Middle);
            if (b.vx > 0) {
                b.vx = -0.7 * b.vx;
                b.vy = b.vy * -1.2;
            }
            else {
                console.log("else!")
                b.vy *= this.bounce;
            }
            return false;
        }
        if (this.HypotenuseRight1(b.nextX, b.nextY) == 2) {
            //var channel: egret.SoundChannel = this.soundzhuangbian.play(0, 1);
            var v = Math.sqrt(b.vx * b.vx + b.vy * b.vy) / 2;
            if (v > 1) v = 1;
            //channel.volume = v;
            angle = this.GetAngle(this.trapezoid_H, this.trapezoid_Middle);

            if (b.vy < 0) {
                b.vy = -0.5;
                b.vx = -1;
            }
            return false;
        }
        if (this.HypotenuseLeft2(b.nextX, b.nextY) == 2) {
            //var channel: egret.SoundChannel = this.soundzhuangbian.play(0, 1);
            var v = Math.sqrt(b.vx * b.vx + b.vy * b.vy) / 2;
            if (v > 1) v = 1;
            //channel.volume = v;
            // channel.volume = Math.sqrt(b.vx * b.vx + b.vy * b.vy) / 2;
            angle = this.GetAngle(this.trapezoid_H, this.trapezoid_Long);

            if (b.vy < 0) {
                b.vy = 0;
                b.vx = 1;
            }
            return false;
        }
        if (b.nextX <= this.posArr[0].x1) {
            var dx: number = b.nextX - this.posArr[0].x1;
            var dy: number = b.nextY - this.posArr[0].y1;
            var dist: number = Math.sqrt(dx * dx + dy * dy);
            if (dist < this._r) {
                this.rebound(b, this.posArr[0].x1, this.posArr[0].y1, 0.7);
            }
        }
        if (b.nextX >= this.posArr[1].x1 && b.nextX < this.posArr[1].hx) {
            var dx: number = b.nextX - this.posArr[1].x1;
            var dy: number = b.nextY - this.posArr[1].y1;
            var dist: number = Math.sqrt(dx * dx + dy * dy);
            if (dist < this._r) {
                this.rebound(b, this.posArr[1].x1, this.posArr[1].y1, 0.7);
            }
        }
        if (b.nextX <= this.posArr[1].x2 && b.nextX > this.posArr[1].hx) {
            var dx: number = b.nextX - this.posArr[1].x2;
            var dy: number = b.nextY - this.posArr[1].y2;
            var dist: number = Math.sqrt(dx * dx + dy * dy);
            if (dist < this._r) {
                this.rebound(b, this.posArr[1].x2, this.posArr[1].y2, 0.7);
            }
        }
        if (b.nextX >= this.posArr[2].x1) {
            var dx: number = b.nextX - this.posArr[2].x1;
            var dy: number = b.nextY - this.posArr[2].y1;
            var dist: number = Math.sqrt(dx * dx + dy * dy);
            if (dist < this._r) {
                this.rebound(b, this.posArr[2].x1, this.posArr[2].y1, 0.7);
            }
        }
        //下边



        if (this.EdgeTesting(b.nextX, b.nextY) == 3 || this.HypotenuseRight3(b.nextX, b.nextY) == 1 || this.HypotenuseLeft5(b.nextX, b.nextY) == 1) {
            b.nextY = this.posArr[3].y4 - this._r;
            //var channel: egret.SoundChannel = this.soundzhuangbian.play(0, 1);
            var v = Math.sqrt(b.vx * b.vx + b.vy * b.vy) / 2;
            if (v > 1) v = 1;
            //channel.volume = v;
            // channel.volume = Math.sqrt(b.vx * b.vx + b.vy * b.vy) / 2;
            b.vy *= this.bounce;
        }
        if (this.HypotenuseRight3(b.nextX, b.nextY) == 2) {
            //var channel: egret.SoundChannel = this.soundzhuangbian.play(0, 1);
            var v = Math.sqrt(b.vx * b.vx + b.vy * b.vy) / 2;
            if (v > 1) v = 1;
            //channel.volume = v;
            // channel.volume = Math.sqrt(b.vx * b.vx + b.vy * b.vy) / 2;
            angle = this.GetAngle(this.trapezoid_H, this.trapezoid_Long);

            if (b.vy > 0) {
                b.vy = 0;
                b.vx = -1;
            }
            return false;
        }
        if (this.HypotenuseLeft4(b.nextX, b.nextY) == 1) {
            //var channel: egret.SoundChannel = this.soundzhuangbian.play(0, 1);
            var v = Math.sqrt(b.vx * b.vx + b.vy * b.vy) / 2;
            if (v > 1) v = 1;
            //channel.volume = v;
            // channel.volume = Math.sqrt(b.vx * b.vx + b.vy * b.vy) / 2;
            // angle = this.GetAngle(this.trapezoid_H, this.trapezoid_Middle);
            if (b.vx < 0) {
                b.vx = -0.7 * b.vx;
                b.vy = b.vy * -1.2;
            }
            else {
                console.log("else!")
                b.vy *= this.bounce;
            }
            return false;
        }
        if (this.HypotenuseLeft4(b.nextX, b.nextY) == 2) {
            //var channel: egret.SoundChannel = this.soundzhuangbian.play(0, 1);
            var v = Math.sqrt(b.vx * b.vx + b.vy * b.vy) / 2;
            if (v > 1) v = 1;
            //channel.volume = v;
            // channel.volume = Math.sqrt(b.vx * b.vx + b.vy * b.vy) / 2;
            angle = this.GetAngle(this.trapezoid_H, this.trapezoid_Middle);

            if (b.vy > 0) {
                b.vy = 0.5;
                b.vx = 1;
            }
            return false;
        }
        if (this.HypotenuseRight4(b.nextX, b.nextY) == 1) {
            //var channel: egret.SoundChannel = this.soundzhuangbian.play(0, 1);

            var v = Math.sqrt(b.vx * b.vx + b.vy * b.vy) / 2;
            if (v > 1) v = 1;
            //channel.volume = v;
            // channel.volume = Math.sqrt(b.vx * b.vx + b.vy * b.vy) / 2;
            // angle = this.GetAngle(this.trapezoid_H, this.trapezoid_Middle);
            if (b.vx > 0) {
                b.vx = -0.7 * b.vx;
                b.vy = b.vy * -1.2;
            }
            else {
                console.log("else!")
                b.vy *= this.bounce;
            }
            return false;
        }
        if (this.HypotenuseRight4(b.nextX, b.nextY) == 2) {
            //var channel: egret.SoundChannel = this.soundzhuangbian.play(0, 1);
            var v = Math.sqrt(b.vx * b.vx + b.vy * b.vy) / 2;
            if (v > 1) v = 1;
            //channel.volume = v;
            angle = this.GetAngle(this.trapezoid_H, this.trapezoid_Middle);

            if (b.vy > 0) {
                b.vy = 0.5;
                b.vx = -1;
            }
            return false;
        }
        if (this.HypotenuseLeft5(b.nextX, b.nextY) == 2) {
            //var channel: egret.SoundChannel = this.soundzhuangbian.play(0, 1);
            var v = Math.sqrt(b.vx * b.vx + b.vy * b.vy) / 2;
            if (v > 1) v = 1;
            //channel.volume = v;
            angle = this.GetAngle(this.trapezoid_H, this.trapezoid_Long);

            if (b.vy > 0) {
                b.vy = 0;
                b.vx = 1;
            }
            return false;
        }
        if (b.nextX <= this.posArr[3].x2) {
            var dx: number = b.nextX - this.posArr[3].x2;
            var dy: number = b.nextY - this.posArr[3].y2;
            var dist: number = Math.sqrt(dx * dx + dy * dy);
            if (dist < this._r) {
                this.rebound(b, this.posArr[3].x2, this.posArr[3].y2, 0.7);
            }
        }
        if (b.nextX >= this.posArr[4].x1 && b.nextX < this.posArr[4].hx) {
            var dx: number = b.nextX - this.posArr[4].x1;
            var dy: number = b.nextY - this.posArr[4].y1;
            var dist: number = Math.sqrt(dx * dx + dy * dy);
            if (dist < this._r) {
                this.rebound(b, this.posArr[4].x1, this.posArr[4].y1, 0.7);
            }
        }
        if (b.nextX <= this.posArr[4].x2 && b.nextX > this.posArr[4].hx) {
            var dx: number = b.nextX - this.posArr[4].x2;
            var dy: number = b.nextY - this.posArr[4].y2;
            var dist: number = Math.sqrt(dx * dx + dy * dy);
            if (dist < this._r) {
                this.rebound(b, this.posArr[4].x2, this.posArr[4].y2, 0.7);
            }
        }
        if (b.nextX >= this.posArr[5].x2) {
            var dx: number = b.nextX - this.posArr[5].x2;
            var dy: number = b.nextY - this.posArr[5].y2;
            var dist: number = Math.sqrt(dx * dx + dy * dy);
            if (dist < this._r) {
                this.rebound(b, this.posArr[5].x2, this.posArr[5].y2, 0.7);
            }
        }

    }


    //划线部分
    private setSubline() {
        var v: number = 2;

        var vx: number = 0;
        var vy: number = 0;

        //计算球的速度
        if (this.angleNum == 1) {
            vx = v * Math.sin(this.angleSpeed);
            vy = -v * Math.cos(this.angleSpeed);
        }
        else if (this.angleNum == 2) {
            vx = v * Math.cos(this.angleSpeed);
            vy = v * Math.sin(this.angleSpeed);
        }
        else if (this.angleNum == 3) {
            vx = v * Math.sin(this.angleSpeed);
            vy = -v * Math.cos(this.angleSpeed);
        }
        else if (this.angleNum == 4) {
            vx = -v * Math.cos(this.angleSpeed);
            vy = v * Math.sin(this.angleSpeed);
        }

        this.shp1.graphics.clear();
        this.shp2.graphics.clear();
        this.shp2_2.graphics.clear();
        this.shp3.graphics.clear();
        this.shp4.graphics.clear();
        this.shp5.graphics.clear();

        var px: number = this.curBall.nextX;
        var py: number = this.curBall.nextY;
        /**偏移方向 */
        let direction: egret.Point = new egret.Point();
        //每一步计算划线的下一点
        for (var i: number = 0; i < 1500; i++) {
            px += vx;
            py += vy;
            // console.log(px+",,,,,,"+i);
            // console.log(py+",,,,,,"+i);
            var len: number = this.ballArr.length;
            var is: boolean = false;
            //遍历所有的球
            //判断是否碰到其他彩球
            for (var j: number = 0; j < len; j++) {
                var ballA: NewBall = this.ballArr[j];
                if (ballA.name == "cur") {
                    continue;
                }
                var dx: number = ballA.nextX - px;//px是白球的坐标 nextX是其他球的坐标
                var dy: number = ballA.nextY - py;
                var dist: number = Math.sqrt(dx * dx + dy * dy);//两球之间的距离


                //距离<球的半径，代表碰到球了 
                if (dist <= 2 * this._r) {
                    is = true;
                    var a1: any = this.rotationCoord(px, py, this.huadongAngle);
                    var a2: any = this.rotationCoord(ballA.nextX, ballA.nextY, this.huadongAngle);

                    var dx0: number = a1.x - a2.x;
                    var dy0: number = a1.y - a2.y;
                    var dist0: number = Math.sqrt(dx0 * dx0 + dy0 * dy0);
                    var asd: number = Math.abs(dx0 / dist0);
                    var num: number = dy0 / Math.abs(dy0);

                    //计算两点之间的X与Y轴的距离计算出来两点之间的斜率角度
                    var angle: number = Math.atan2(dy, dx);
                    var sin: number = Math.sin(angle);
                    var cos: number = Math.cos(angle);
                    var pos1: egret.Point = this.rotateR(dx, dy, sin, cos, true);

                    pos1.x += 70 * asd;

                    var pos2: egret.Point = new egret.Point(0, num * (this._r + 50 * (1 - asd)));

                    var pos3: egret.Point = new egret.Point(0, num * this._r);

                    var pos1F: any = this.rotateR(pos1.x, pos1.y, sin, cos, false);

                    var pos2F: any = this.rotateR(pos2.x, pos2.y, sin, cos, false);

                    var pos3F: any = this.rotateR(pos3.x, pos3.y, sin, cos, false);

                    //已弃用
                    this.shp3.graphics.lineStyle(0.5, 0xFFFFFF);//红线  被碰到的球的走向   0xFFFF00
                    direction.setTo(pos1F.x, pos1F.y);
                    direction.normalize(this._r);
                    this.shp3.graphics.moveTo(ballA.nextX + direction.x, ballA.nextY + direction.y);
                    this.shp3.graphics.lineTo(px + pos1F.x, py + pos1F.y);
                    this.shp3.graphics.endFill();

                    this.shp4.graphics.lineStyle(1.5, 0xFFFFFF);//蓝线  白球走向  0x0000FF
                    direction.setTo(pos2F.x, pos2F.y);
                    direction.normalize(this._r);
                    this.shp4.graphics.moveTo(px + direction.x, py + direction.y);//起点
                    this.shp4.graphics.lineTo(px + pos2F.x, py + pos2F.y);//终点
                    this.shp4.graphics.endFill();
                    break;
                }

            }
            if (is) {
                break;
            }
            //判断是否碰到球洞
            var have: boolean = true;

            for (var i: number = 0; i < 6; i++) {
                var _hx: number = this.posArr[i].hx;
                var _hy: number = this.posArr[i].hy;
                if (px > _hx - this.holeR && px < _hx + this.holeR && py > _hy - this.holeR && py < _hy + this.holeR) {
                    var dx: number = px - _hx;
                    var dy: number = py - _hy;
                    var dist: number = Math.sqrt(dx * dx + dy * dy);
                    if (dist < this.holeR) {
                        have = false;
                        break;
                    }
                }
            }
            if (!have) {
                break;
            }
            //判断是否碰到四周的直线球案

            if (this.EdgeTesting(px, py)) {
                break;
            }
            //
            //
            //判断是否碰到四周的斜边
            //正在斜边的运动轨迹中px，py的运动轨迹由圆弧和直线组成



            //零号洞右边斜边三号洞右边斜边
            if (this.HypotenuseRight0(px, py)) {
                break;
            }
            if (this.HypotenuseRight3(px, py)) {
                break;
            }

            //零号洞下边斜边二号洞下边斜边
            if (this.HypotenuseDown0(px, py)) {
                break;
            }
            if (this.HypotenuseDown2(px, py)) {
                break;
            }




            //三号洞上边斜边和五号洞上边斜边
            if (this.HypotenuseUp3(px, py)) {
                break;
            }
            if (this.HypotenuseUp5(px, py)) {
                break;
            }



            //二号洞的左边斜边和五号洞的左边斜边
            if (this.HypotenuseLeft2(px, py)) {
                break;
            }
            if (this.HypotenuseLeft5(px, py)) {
                break;
            }



            //一号洞左边斜边和四号洞左边斜边
            if (this.HypotenuseLeft1(px, py)) {
                break;
            }
            if (this.HypotenuseLeft4(px, py)) {
                break;
            }

            //一号洞的右边斜边和四号洞右边斜边
            if (this.HypotenuseRight1(px, py)) {
                break;
            }
            if (this.HypotenuseRight4(px, py)) {
                break;
            }

        }

        this.shp1.graphics.lineStyle(1.5, 0xFFFFFF);
        direction.setTo(px - this.curBall.nextX, py - this.curBall.nextY);
        direction.normalize(this._r);
        //起点
        this.shp1.graphics.moveTo(this.curBall.nextX + direction.x, this.curBall.nextY + direction.y);
        //起点
        var _sx = this.curBall.nextX + direction.x;
        var _sy = this.curBall.nextY + direction.y;


        direction.setTo(this.curBall.nextX - px, this.curBall.nextY - py);
        direction.normalize(this._r);
        //终端
        this.shp1.graphics.lineTo(px + direction.x, py + direction.y);
        this.shp1.graphics.endFill();
        // this.shp1.graphics.clear();

        this.lin1.x = _sx;
        this.lin1.y = _sy;
        //终端
        var _nx = px + direction.x;
        var _ny = py + direction.y;
        // this.setlinpic(_sx, _sy, _nx, _ny, this.lin1);



        this.shp2.graphics.lineStyle(1, 0xFFFFFF);
        this.shp2.graphics.drawCircle(px, py, this._r - 1);//白球第一次碰撞位置
        this.shp2.graphics.endFill();

        // direction.setTo(px - this.curBall.nextX, py - this.curBall.nextY);
        //direction.normalize(7);
        // this.shp2.graphics.clear();
        // this.setcirpic(px, py, this.lin2);



        //折线部分
        if (dist > 2 * this._r) {
            this.Brokenline1(px, py);//调用画折线的方法
        }
        // if (dist > 2 * this._r) {
        //     if(px>this.posArr[0].x4&&px<this.posArr[1].x4)
        //     {
        //         this.Brokenline1(px,py);
        //     }
        //     else  if(px>this.posArr[1].x3&&px<this.posArr[2].x3)
        //     {
        //         this.Brokenline1(px,py);
        //     }

        // }
    }
    private rotateR(x: number, y: number, sin: number, cos: number, reverse: Boolean): egret.Point {
        var result: egret.Point = new egret.Point();
        if (reverse) {
            result.x = x * cos + y * sin;
            result.y = y * cos - x * sin;
        } else {
            result.x = x * cos - y * sin;
            result.y = y * cos + x * sin;
        }
        return result;
    }

    private checkCollision(ball0: NewBall, ball1: NewBall) {
        var dx: number = ball1.nextX - ball0.nextX;
        var dy: number = ball1.nextY - ball0.nextY;
        var dist: number = Math.sqrt(dx * dx + dy * dy);
        if (dist < 2 * this._r) {

            var _vxx: number = ball0.vx + ball1.vx;
            var _vyy: number = ball0.vy + ball1.vy;
            // var channel: egret.SoundChannel = this.soundzhuangqiu.play(0, 1);

            var v = Math.sqrt(_vxx * _vxx + _vyy * _vyy) / 2;
            this.PlaySoundWithVolume(v, TableUI.Instance().ballCrashsSound);
            // if (v > 1) v = 1;
            // //channel.volume = v;
            // channel.volume = Math.sqrt(_vxx * _vxx + _vyy * _vyy) / 2;

            var angle: number = Math.atan2(dy, dx);
            var sin: number = Math.sin(angle);
            var cos: number = Math.cos(angle);

            var pos0: egret.Point = new egret.Point(0, 0);
            var pos1: egret.Point = this.rotateR(dx, dy, sin, cos, true);

            var vel0: egret.Point = this.rotateR(ball0.vx, ball0.vy, sin, cos, true);
            var vel1: egret.Point = this.rotateR(ball1.vx, ball1.vy, sin, cos, true);

            var overlap: number = 2 * this._r - Math.abs(pos0.x - pos1.x);

            pos0.x -= 0.5 * overlap + 0.0001;
            pos1.x += 0.5 * overlap + 0.0001;

            var pos0F: any = this.rotateR(pos0.x, pos0.y, sin, cos, false);
            var pos1F: any = this.rotateR(pos1.x, pos1.y, sin, cos, false);
            ball1.nextX = ball0.nextX + pos1F.x;
            ball1.nextY = ball0.nextY + pos1F.y;
            ball0.nextX = ball0.nextX + pos0F.x;
            ball0.nextY = ball0.nextY + pos0F.y;

            var vxTotal: number = vel0.x - vel1.x;
            vel0.x = vel1.x;
            vel1.x = vxTotal + vel0.x;

            var vel0F: any = this.rotateR(vel0.x, vel0.y, sin, cos, false);
            var vel1F: any = this.rotateR(vel1.x, vel1.y, sin, cos, false);
            ball0.vx = vel0F.x;
            ball0.vy = vel0F.y;
            ball1.vx = vel1F.x;
            ball1.vy = vel1F.y;
            if (this.firstCollision == 0) {
                if (ball0.idx == 0) {
                    this.firstCollision = ball1.idx;
                }
                if (ball1.idx == 0) {
                    this.firstCollision = ball0.idx;
                }
            }
        }
    }

    private rebound(ball0: NewBall, _x, _y, num) {
        if (num == 0) {
            ball0.vx = 0;
            ball0.vy = 0;
            return;
        }

        //var channel: egret.SoundChannel = this.soundzhuangbian.play(0, 1);
        var v = Math.sqrt(ball0.vx * ball0.vx + ball0.vy * ball0.vy) / 2;
        if (v > 1) v = 1;
        //channel.volume = v;
        // channel.volume = Math.sqrt(ball0.vx * ball0.vx + ball0.vy * ball0.vy) / 2;

        var dx: number = _x - ball0.nextX;
        var dy: number = _y - ball0.nextY;
        var angle: number = Math.atan2(dy, dx);
        var sin: number = Math.sin(angle);
        var cos: number = Math.cos(angle);

        var pos0: egret.Point = new egret.Point(0, 0);
        var pos1: egret.Point = this.rotateR(dx, dy, sin, cos, true);
        pos0.x = pos1.x - this._r - 0.0001;
        var pos0F: any = this.rotateR(pos0.x, pos0.y, sin, cos, false);
        ball0.nextX = ball0.nextX + pos0F.x;
        ball0.nextY = ball0.nextY + pos0F.y;

        var vel0: egret.Point = this.rotateR(ball0.vx, ball0.vy, sin, cos, true);
        var vel1: egret.Point = this.rotateR(0, 0, sin, cos, true);
        var vxTotal: number = vel0.x - vel1.x;
        vel0.x = vel1.x;
        vel1.x = vxTotal + vel0.x;
        var vel0F: any = this.rotateR(vel0.x, vel0.y, sin, cos, false);
        var vel1F: any = this.rotateR(vel1.x, vel1.y, sin, cos, false);
        ball0.vx = num * (vel0F.x - vel1F.x);
        ball0.vy = num * (vel0F.y - vel1F.y);
    }

    private setTimeNum(_num: number) {
        if (_num < 0 || _num >= 100) {
            return;
        }
        var num: number = Math.floor(_num);
        var leftNum: number = Math.floor(num / 10);
        var rightNum: number = num - leftNum * 10;

        this.leftNumImg.source = "num" + leftNum;
        this.rightNumImg.source = "num" + rightNum;
    }


    private BrokenLine() {

    }
    private reflex(pos1: number[], pos2: number[]) {
        // this.shp5.graphics.lineStyle(3, 0xF00FFF);
        // this.shp5.graphics.moveTo(pos1[0], pos1[1]);//起点
        // this.shp5.graphics.lineTo(pos2[0], pos2[1]);//终点
        // this.shp5.graphics.endFill();
    }
    /**
     * px:第一个白圆圈的X坐标py:第一个白圆圈的Y坐标companyX:折线的单位X坐标companyY:折线的单位Y坐标
     * 划折线部分
     */
    private CollisionDetection(px: number, py: number, companyX: number, companyY: number) {
        var px1 = px;
        var py1 = py;
        var edge1 = 0;
        /**偏移方向 */
        let direction: egret.Point = new egret.Point();
        for (var i: number = 0; i < 1500; i++) {
            px1 += companyX;
            py1 += companyY;
            // console.log(px+",,,,,,"+i);
            // console.log(py+",,,,,,"+i);
            var len: number = this.ballArr.length;
            var is: boolean = false;
            //遍历所有的球
            for (var j: number = 0; j < len; j++) {
                var ballA: NewBall = this.ballArr[j];
                if (ballA.name == "cur") {
                    continue;
                }
                var dx: number = ballA.nextX - px1;//px是白球的坐标 nextX是其他球的坐标
                var dy: number = ballA.nextY - py1;
                var dist: number = Math.sqrt(dx * dx + dy * dy);//两球之间的距离


                //距离<球的半径，代表碰到球了
                if (dist <= 2 * this._r) {
                    is = true;
                    var a1: any = this.rotationCoord(px1, py1, this.huadongAngle);
                    var a2: any = this.rotationCoord(ballA.nextX, ballA.nextY, this.huadongAngle);

                    var dx0: number = a1.x - a2.x;
                    var dy0: number = a1.y - a2.y;
                    var dist0: number = Math.sqrt(dx0 * dx0 + dy0 * dy0);
                    var asd: number = Math.abs(dx0 / dist0);
                    var num: number = dy0 / Math.abs(dy0);

                    //计算两点之间的X与Y轴的距离计算出来两点之间的斜率角度
                    var angle: number = Math.atan2(dy, dx);
                    var sin: number = Math.sin(angle);
                    var cos: number = Math.cos(angle);
                    var pos1: egret.Point = this.rotateR(dx, dy, sin, cos, true);

                    pos1.x += 70 * asd;

                    var pos2: egret.Point = new egret.Point(0, num * (this._r + 50 * (1 - asd)));

                    var pos3: egret.Point = new egret.Point(0, num * this._r);

                    var pos1F: any = this.rotateR(pos1.x, pos1.y, sin, cos, false);

                    var pos2F: any = this.rotateR(pos2.x, pos2.y, sin, cos, false);

                    var pos3F: any = this.rotateR(pos3.x, pos3.y, sin, cos, false);


                    this.shp3.graphics.lineStyle(0.3, 0xFFFFFF);//彩球走向
                    direction.setTo(pos1F.x, pos1F.y);
                    direction.normalize(this._r);
                    this.shp3.graphics.moveTo(ballA.nextX + direction.x, ballA.nextY + direction.y);
                    this.shp3.graphics.lineTo(px1 + pos1F.x, py1 + pos1F.y);
                    this.shp3.graphics.endFill();

                    this.shp4.graphics.lineStyle(0.3, 0xFFFFFF);//白球走向
                    direction.setTo(pos2F.x, pos2F.y);
                    direction.normalize(this._r);
                    this.shp4.graphics.moveTo(px1 + direction.x, py1 + direction.y);//起点
                    this.shp4.graphics.lineTo(px1 + pos2F.x, py1 + pos2F.y);//终点
                    this.shp4.graphics.endFill();

                    // this.shp2.graphics.lineStyle(1.5, 0xFFFFFF);
                    // this.shp2.graphics.drawCircle(px1, py1, this._r - 2);
                    // this.shp2.graphics.endFill();
                    break;
                }

            }
            if (is) {
                break;
            }
            var have: boolean = true;

            for (var x: number = 0; x < 6; x++) {
                var _hx: number = this.posArr[x].hx;
                var _hy: number = this.posArr[x].hy;
                if (px1 > _hx - this.holeR && px1 < _hx + this.holeR && py1 > _hy - this.holeR && py1 < _hy + this.holeR) {
                    var dx: number = px1 - _hx;
                    var dy: number = py1 - _hy;
                    var dist: number = Math.sqrt(dx * dx + dy * dy);
                    if (dist < this.holeR) {
                        have = false;
                        break;
                    }
                }
            }
            if (!have) {
                break;
            }
            edge1++;
            if (edge1 > 10) {
                //判断是否碰到四周的直线球案
                if (px1 < (this.posArr[0].x3 + this._r) && py1 >= this.posArr[0].y3 && py1 <= this.posArr[3].y3) {//
                    break;
                }
                if (px1 > (this.posArr[2].x4 - this._r) && py1 >= this.posArr[2].y4 && py1 <= this.posArr[5].y4) {//
                    break;
                }
                if ((py1 < this.posArr[0].y4 + this._r && px1 >= this.posArr[0].x4 && px1 <= this.posArr[1].x4) || (py1 < this.posArr[0].y4 + this._r && px1 >= this.posArr[1].x3 && px1 <= this.posArr[2].x3)) {
                    break;
                }
                if ((py1 > this.posArr[3].y4 - this._r && px1 >= this.posArr[0].x4 && px1 <= this.posArr[1].x4) || (py1 > this.posArr[3].y4 - this._r && px1 >= this.posArr[4].x3 && px1 <= this.posArr[5].x3)) {
                    break;
                }
                //
                //
                //判断是否碰到四周的斜边
                //正在斜边的运动轨迹中px，py的运动轨迹由圆弧和直线组成



                //零号洞右边斜边三号洞右边斜边
                var angle_Trapezoid = this.GetAngle(this.trapezoid_H, this.trapezoid_Long);//获得斜边的弧度制
                var pos_X = new Array(2);//储存X的值域的变量
                var pos_Y = new Array(2);//储存Y的值域的变量
                // console.log(angle_Trapezoid);
                pos_X = this.CircularRange(this._r, angle_Trapezoid, this.posArr[0].x4, 2);
                //  console.log(pos_X[0],pos_X[1])
                //判断圆弧轨迹的碰撞
                if (px1 >= pos_X[0] && px1 <= pos_X[1]) {
                    var Circular_Y1 = this.EquationOfCircle(this.posArr[0].x4, this.posArr[0].y4, this._r, px1, 1);
                    var Circular_Y2 = this.EquationOfCircle(this.posArr[3].x4, this.posArr[3].y4, this._r, px1, 2);
                    // console.log("x的值域",pos_X[0],pos_X[1]);
                    // console.log("圆周上y的值",Circular_Y);
                    // console.log("py",py);
                    if (py1 <= Circular_Y1) {
                        // console.log("222222222222222222222");
                        // console.log("px",px);
                        // console.log("py",py);
                        // console.log("firstCollision",Circular_Y)
                        // console.log("222222222222222222222");
                        break;
                    }
                    else if (py1 >= Circular_Y2) {
                        break;
                    }
                }
                //判断斜边区域直线运动轨迹的碰撞
                if (px1 <= pos_X[0]) {
                    //获得圆心运动轨迹的一次函数上关于px的Y值
                    var firstOrderFunction_Y1 = this.FirstOrderFunction(this.posArr[0].x1, this.posArr[0].y1, this.posArr[0].x4, this.posArr[0].y4, this._r / Math.cos(angle_Trapezoid), px1, 1);
                    // console.log("px",px);
                    // console.log("py",py);
                    // console.log("firstCollision",firstOrderFunction_Y)
                    var firstOrderFunction_Y2 = this.FirstOrderFunction(this.posArr[3].x2, this.posArr[3].y2, this.posArr[3].x4, this.posArr[3].y4, -this._r / Math.cos(angle_Trapezoid), px1, 1);
                    if (py1 <= firstOrderFunction_Y1) {
                        // console.log("11111111111111111111");
                        // console.log("px",px);
                        // console.log("py",py);
                        // console.log("firstCollision",firstOrderFunction_Y)
                        // console.log("11111111111111111111");
                        break;
                    }
                    if (py1 >= firstOrderFunction_Y2) {
                        break;
                    }
                }


                //零号洞下边斜边二号洞下边斜边




                // var angle_Trapezoid=this.GetTrapezoidAngle(this.trapezoid_H,this.trapezoid_Long);//获得斜边的弧度制
                pos_Y = this.CircularRange(this._r, angle_Trapezoid, this.posArr[0].y3, 2);
                //判断圆弧轨迹的碰撞
                if (py1 >= pos_Y[0] && py1 <= pos_Y[1]) {
                    var Circular_X1 = this.EquationOfCircle(this.posArr[0].x3, this.posArr[0].y3, this._r, py1, 3);
                    var Circular_X2 = this.EquationOfCircle(this.posArr[2].x4, this.posArr[2].y4, this._r, py1, 4);
                    //  console.log("y的值域",pos_Y[0],pos_Y[1]);
                    //  console.log("圆周上y的值",Circular_X2);
                    //  console.log("py",py);
                    //  console.log("px",px);
                    if (px1 <= Circular_X1) {
                        break;
                    }
                    if (px1 >= Circular_X2) {
                        break;
                    }
                }
                //判断斜边区域直线运动轨迹的碰撞
                if (py1 <= pos_Y[0]) {
                    //获得圆心运动轨迹的一次函数
                    var firstOrderFunction_X1 = this.FirstOrderFunction(this.posArr[0].x2, this.posArr[0].y2, this.posArr[0].x3, this.posArr[0].y3, -this._r / Math.sin(angle_Trapezoid), py1, 2);
                    var firstOrderFunction_X2 = this.FirstOrderFunction(this.posArr[2].x2, this.posArr[2].y2, this.posArr[2].x4, this.posArr[2].y4, -this._r / Math.sin(angle_Trapezoid), py1, 2)
                    if (px1 <= firstOrderFunction_X1) {
                        break;
                    }
                    if (px1 >= firstOrderFunction_X2) {
                        break;
                    }
                }




                //三号洞上边斜边和五号洞上边斜边
                pos_Y = this.CircularRange(this._r, angle_Trapezoid, this.posArr[3].y3, 1);
                //判断圆弧轨迹的碰撞
                if (py1 >= pos_Y[0] && py1 <= pos_Y[1]) {
                    Circular_X1 = this.EquationOfCircle(this.posArr[3].x3, this.posArr[3].y3, this._r, py1, 3);
                    Circular_X2 = this.EquationOfCircle(this.posArr[5].x4, this.posArr[5].y4, this._r, py1, 4);
                    //  console.log("y的值域",pos_Y[0],pos_Y[1]);
                    //  console.log("圆周上y的值",Circular_X);
                    //  console.log("py",py);
                    //  console.log("px",px);
                    if (px1 <= Circular_X1) {
                        break;
                    }
                    if (px1 >= Circular_X2) {
                        break;
                    }
                }
                //判断斜边区域直线运动轨迹的碰撞
                if (py1 >= pos_Y[1]) {
                    //获得圆心运动轨迹的一次函数
                    firstOrderFunction_X1 = this.FirstOrderFunction(this.posArr[3].x1, this.posArr[3].y1, this.posArr[3].x3, this.posArr[3].y3, this._r / Math.sin(angle_Trapezoid), py1, 2);
                    firstOrderFunction_X2 = this.FirstOrderFunction(this.posArr[5].x1, this.posArr[5].y1, this.posArr[5].x4, this.posArr[5].y4, this._r / Math.sin(angle_Trapezoid), py1, 2)
                    if (px1 <= firstOrderFunction_X1) {
                        break;
                    }
                    if (px1 >= firstOrderFunction_X2) {
                        break;
                    }
                }



                //二号洞的左边斜边和五号洞的左边斜边
                pos_X = this.CircularRange(this._r, angle_Trapezoid, this.posArr[2].x3, 1);
                //判断圆弧轨迹的碰撞
                if (px1 >= pos_X[0] && px1 <= pos_X[1]) {
                    var Circular_Y1 = this.EquationOfCircle(this.posArr[2].x3, this.posArr[2].y3, this._r, px1, 1);
                    var Circular_Y2 = this.EquationOfCircle(this.posArr[5].x3, this.posArr[5].y3, this._r, px1, 2);
                    // console.log("y的值域", pos_Y[0], pos_Y[1]);
                    //console.log("圆周上y的值", Circular_Y1);
                    //console.log("py", py);
                    // console.log("px", px);
                    if (py1 <= Circular_Y1) {
                        break;
                    }
                    else if (py1 >= Circular_Y2) {
                        break;
                    }
                }

                //判断斜边区域直线运动轨迹的碰撞
                if (px1 >= pos_X[1]) {
                    //获得圆心运动轨迹的一次函数上关于px的Y值
                    var firstOrderFunction_Y1 = this.FirstOrderFunction(this.posArr[2].x1, this.posArr[2].y1, this.posArr[2].x3, this.posArr[2].y3, this._r / Math.cos(angle_Trapezoid), px1, 1);
                    var firstOrderFunction_Y2 = this.FirstOrderFunction(this.posArr[5].x2, this.posArr[5].y2, this.posArr[5].x3, this.posArr[5].y3, -this._r / Math.cos(angle_Trapezoid), px1, 1);
                    // console.log("px:", px);
                    // console.log("py:", py);
                    //console.log("firstOrderFunction_Y1:", firstOrderFunction_Y1);
                    if (py1 <= firstOrderFunction_Y1) {
                        break;
                    }
                    if (py1 >= firstOrderFunction_Y2) {
                        break;
                    }
                }



                //一号洞右边斜边和四号洞右边斜边
                var angle_Trapezoid1 = this.GetAngle(this.trapezoid_H, this.trapezoid_Middle);//获得斜边的弧度制
                pos_X = this.CircularRange(this._r, angle_Trapezoid1, this.posArr[1].x4, 1);
                if (px1 >= pos_X[0] && px1 <= pos_X[1]) {
                    Circular_Y1 = this.EquationOfCircle(this.posArr[1].x4, this.posArr[1].y4, this._r, px1, 1);
                    Circular_Y2 = this.EquationOfCircle(this.posArr[4].x4, this.posArr[4].y4, this._r, px1, 2);
                    if (py1 <= Circular_Y1) {
                        break;
                    }
                    else if (py1 >= Circular_Y2) {
                        break;
                    }
                }
                //判断斜边区域直线运动轨迹的碰撞
                if (px1 >= pos_X[1]) {
                    //获得圆心运动轨迹的一次函数上关于px的Y值
                    firstOrderFunction_Y1 = this.FirstOrderFunction(this.posArr[1].x1, this.posArr[1].y1, this.posArr[1].x4, this.posArr[1].y4, this._r / Math.cos(angle_Trapezoid1), px1, 1);
                    firstOrderFunction_Y2 = this.FirstOrderFunction(this.posArr[4].x1, this.posArr[4].y1, this.posArr[4].x4, this.posArr[4].y4, -this._r / Math.cos(angle_Trapezoid1), px1, 1);
                    if (py1 <= firstOrderFunction_Y1) {
                        // console.log("11111111111111111111");
                        // console.log("px",px);
                        // console.log("py",py);
                        // console.log("firstCollision",firstOrderFunction_Y)
                        // console.log("11111111111111111111");
                        break;
                    }
                    if (py1 >= firstOrderFunction_Y2) {
                        break;
                    }
                }

                //一号洞的右边斜边和四号洞右边斜边
                pos_X = this.CircularRange(this._r, angle_Trapezoid1, this.posArr[1].x3, 2);
                if (px1 >= pos_X[0] && px1 <= pos_X[1]) {
                    Circular_Y1 = this.EquationOfCircle(this.posArr[1].x3, this.posArr[1].y3, this._r, px1, 1);
                    Circular_Y2 = this.EquationOfCircle(this.posArr[4].x3, this.posArr[4].y3, this._r, px1, 2);
                    if (py1 <= Circular_Y1) {
                        break;
                    }
                    else if (py1 >= Circular_Y2) {
                        break;
                    }
                }
                //判断斜边区域直线运动轨迹的碰撞
                if (px1 <= pos_X[0]) {
                    //获得圆心运动轨迹的一次函数上关于px的Y值
                    firstOrderFunction_Y1 = this.FirstOrderFunction(this.posArr[1].x2, this.posArr[1].y2, this.posArr[1].x3, this.posArr[1].y3, this._r / Math.cos(angle_Trapezoid1), px1, 1);
                    firstOrderFunction_Y2 = this.FirstOrderFunction(this.posArr[4].x2, this.posArr[4].y2, this.posArr[4].x3, this.posArr[4].y3, -this._r / Math.cos(angle_Trapezoid1), px1, 1);
                    if (py1 <= firstOrderFunction_Y1) {
                        // console.log("11111111111111111111");
                        // console.log("px",px);
                        // console.log("py",py);
                        // console.log("firstCollision",firstOrderFunction_Y)
                        // console.log("11111111111111111111");
                        break;
                    }
                    if (py1 >= firstOrderFunction_Y2) {
                        break;
                    }
                }
            }
        }
        //console.log(px1+","+py1);


        this.shp1.graphics.lineStyle(1.5, 0xFFFFFF);//白球第二段走向   
        direction.setTo(px1 - px, py1 - py);
        direction.normalize(this._r);
        this.shp1.graphics.moveTo(px + direction.x, py + direction.y);
        var __sx = px + direction.x;
        var __sy = py + direction.y;

        direction.setTo(px - px1, py - py1);
        direction.normalize(this._r);
        this.shp1.graphics.lineTo(px1 + direction.x, py1 + direction.y);
        var __nx = px1 + direction.x;
        var __ny = py1 + direction.y;
        this.setlinpic(__sx, __sy, __nx, __ny, this.lin3);

        this.shp1.graphics.endFill();
        // this.shp1.graphics.clear();



        this.shp2_2.graphics.lineStyle(0.3, 0xFFFFFF);
        this.shp2_2.graphics.drawCircle(px1, py1, this._r - 1);//白球第二次碰撞位置
        this.shp2_2.graphics.endFill();
    }
    private debugDrawTable() {
        var pos1 = new Array(2);
        pos1[0] = this.posArr[0].hx;
        pos1[1] = this.posArr[0].hy;
        var pos2 = new Array(2);
        pos2[0] = this.posArr[2].hx;
        pos2[1] = this.posArr[2].hy;
        var pos3 = new Array(2);
        var pos4 = new Array(2);
        pos3[0] = this.posArr[5].hx;
        pos3[1] = this.posArr[5].hy;
        pos4[0] = this.posArr[3].hx;
        pos4[1] = this.posArr[3].hy;
        var pos5 = new Array(2);
        var pos6 = new Array(2);
        pos5[0] = this.posArr[1].hx;
        pos5[1] = this.posArr[1].hy;
        pos6[0] = this.posArr[4].hx;
        pos6[1] = this.posArr[4].hy;
        var edgePos1 = new Array(2);
        var edgePos2 = new Array(2);
        var edgePos3 = new Array(2);
        var edgePos4 = new Array(2);
        var edgePos5 = new Array(2);
        var edgePos6 = new Array(2);
        var edgePos6 = new Array(2);
        var edgePos7 = new Array(2);
        var edgePos8 = new Array(2);
        var edgePos9 = new Array(2);
        var edgePos10 = new Array(2);
        var edgePos11 = new Array(2);
        var edgePos12 = new Array(2);
        var edgePos13 = new Array(2);
        var edgePos14 = new Array(2);
        var edgePos15 = new Array(2);
        var edgePos16 = new Array(2);
        var edgePos17 = new Array(2);
        var edgePos18 = new Array(2);
        var edgePos19 = new Array(2);
        var edgePos20 = new Array(2);
        var edgePos21 = new Array(2);
        var edgePos22 = new Array(2);
        var edgePos23 = new Array(2);
        var edgePos24 = new Array(2);
        edgePos1[0] = this.posArr[2].x1;
        edgePos1[1] = this.posArr[2].y1;

        edgePos2[0] = this.posArr[2].x3;
        edgePos2[1] = this.posArr[2].y3;

        edgePos3[0] = this.posArr[1].x3;
        edgePos3[1] = this.posArr[1].y3;

        edgePos4[0] = this.posArr[1].x2;
        edgePos4[1] = this.posArr[1].y2;

        edgePos5[0] = this.posArr[1].x1;
        edgePos5[1] = this.posArr[1].y1;

        edgePos6[0] = this.posArr[1].x4;
        edgePos6[1] = this.posArr[1].y4;

        edgePos7[0] = this.posArr[0].x4;
        edgePos7[1] = this.posArr[0].y4;

        edgePos8[0] = this.posArr[0].x1;
        edgePos8[1] = this.posArr[0].y1;

        edgePos9[0] = this.posArr[0].x2;
        edgePos9[1] = this.posArr[0].y2;

        edgePos10[0] = this.posArr[0].x3;
        edgePos10[1] = this.posArr[0].y3;

        edgePos11[0] = this.posArr[3].x3;
        edgePos11[1] = this.posArr[3].y3;

        edgePos12[0] = this.posArr[3].x1;
        edgePos12[1] = this.posArr[3].y1;

        edgePos13[0] = this.posArr[3].x2;
        edgePos13[1] = this.posArr[3].y2;

        edgePos14[0] = this.posArr[3].x4;
        edgePos14[1] = this.posArr[3].y4;


        edgePos15[0] = this.posArr[4].x4;
        edgePos15[1] = this.posArr[4].y4;


        edgePos16[0] = this.posArr[4].x1;
        edgePos16[1] = this.posArr[4].y1;


        edgePos17[0] = this.posArr[4].x2;
        edgePos17[1] = this.posArr[4].y2;


        edgePos18[0] = this.posArr[4].x3;
        edgePos18[1] = this.posArr[4].y3;


        edgePos19[0] = this.posArr[5].x3;
        edgePos19[1] = this.posArr[5].y3;


        edgePos20[0] = this.posArr[5].x2;
        edgePos20[1] = this.posArr[5].y2;


        edgePos21[0] = this.posArr[5].x1;
        edgePos21[1] = this.posArr[5].y1;


        edgePos22[0] = this.posArr[5].x4;
        edgePos22[1] = this.posArr[5].y4;


        edgePos23[0] = this.posArr[2].x4;
        edgePos23[1] = this.posArr[2].y4;


        edgePos24[0] = this.posArr[2].x2;
        edgePos24[1] = this.posArr[2].y2;






        this.debugDrawLine(edgePos1, edgePos2);
        this.debugDrawLine(edgePos2, edgePos3);
        this.debugDrawLine(edgePos3, edgePos4);

        this.debugDrawLine(edgePos5, edgePos6);
        this.debugDrawLine(edgePos6, edgePos7);
        this.debugDrawLine(edgePos7, edgePos8);

        this.debugDrawLine(edgePos9, edgePos10);
        this.debugDrawLine(edgePos10, edgePos11);
        this.debugDrawLine(edgePos11, edgePos12);

        this.debugDrawLine(edgePos13, edgePos14);
        this.debugDrawLine(edgePos14, edgePos15);
        this.debugDrawLine(edgePos15, edgePos16);

        this.debugDrawLine(edgePos17, edgePos18);
        this.debugDrawLine(edgePos18, edgePos19);
        this.debugDrawLine(edgePos19, edgePos20);

        this.debugDrawLine(edgePos21, edgePos22);
        this.debugDrawLine(edgePos22, edgePos23);
        this.debugDrawLine(edgePos23, edgePos24);

        this.debugDrawPoint(pos1);
        this.debugDrawPoint(pos2)
        this.debugDrawPoint(pos3);
        this.debugDrawPoint(pos4);
        this.debugDrawPoint(pos5);
        this.debugDrawPoint(pos6);
    }
    private TrapezoidBallSide(long: number, middle: number, h: number) {
        //左边边临界值
        var lift_x = this.posArr[0].x2;
        //右边边临界值
        var right_x = this.posArr[2].x2;
        //左边x值
        this.posArr[0].x3 = lift_x + h;
        this.posArr[3].x3 = lift_x + h;
        //右边x值
        this.posArr[2].x4 = right_x - h;
        this.posArr[5].x4 = right_x - h;
        //上边边临界值
        var up_y = this.posArr[0].y1;
        //下边边临界值
        var down_y = this.posArr[3].y2;
        //上边y值
        this.posArr[0].y4 = up_y + h;
        this.posArr[1].y4 = up_y + h;
        this.posArr[1].y3 = up_y + h;
        this.posArr[2].y3 = up_y + h;
        //下边y值
        this.posArr[3].y4 = down_y - h;
        this.posArr[4].y4 = down_y - h;
        this.posArr[4].y3 = down_y - h;
        this.posArr[5].y3 = down_y - h;
        //左边y值
        this.posArr[0].y3 = this.posArr[0].y2 + long;
        this.posArr[3].y3 = this.posArr[3].y1 - long
        //右边y值
        this.posArr[2].y4 = this.posArr[2].y2 + long;

        this.posArr[5].y4 = this.posArr[5].y1 - long;
        //上边x值
        this.posArr[0].x4 = this.posArr[0].x1 + long;
        this.posArr[1].x4 = this.posArr[1].x1 - middle;
        this.posArr[1].x3 = this.posArr[1].x2 + middle;
        this.posArr[2].x3 = this.posArr[2].x1 - long;
        //下边x值
        this.posArr[3].x4 = this.posArr[3].x2 + long;
        this.posArr[4].x4 = this.posArr[4].x1 - middle;
        this.posArr[4].x3 = this.posArr[4].x2 + middle;
        this.posArr[5].x3 = this.posArr[5].x2 - long;
    }
    private debugDrawLine(pos1: number[], pos2: number[]) {
        let shp5 = new egret.Shape;
        this.addChild(shp5);
        shp5.graphics.lineStyle(1.5, 0xFFFFFF);
        shp5.graphics.moveTo(pos1[0], pos1[1]);//起点
        shp5.graphics.lineTo(pos2[0], pos2[1]);//终点
        shp5.graphics.endFill();
    }
    private debugDrawPoint(pos1: number[]) {
        let shp5 = new egret.Shape;
        this.addChild(shp5);
        shp5.graphics.lineStyle(1.5, 0xFFFFFF);
        shp5.graphics.drawCircle(pos1[0], pos1[1], this.holeR);
        shp5.graphics.endFill();
    }
    /**对posArr进行调整 */
    private AdjustposArr(holdDist_X: number, holdDist_Y: number, hold_R: number, edge_X: number, edge_Y: number, middleDeviation: number, edge_LongX: number, edge_LongY: number) {
        /**洞纵长 */


        //调整一号洞坐标
        this.posArr[1].hx = this.posArr[0].hx + holdDist_X;
        this.posArr[1].hy = this.posArr[0].hy - middleDeviation;

        this.posArr[1].x1 = this.posArr[0].x1 + edge_X;
        this.posArr[1].y1 = this.posArr[0].y1;

        this.posArr[1].x2 = this.posArr[0].x1 + edge_X + 2 * Math.sqrt(hold_R * hold_R - (this.posArr[0].hy -
            middleDeviation - this.posArr[0].y1) * (this.posArr[0].hy - middleDeviation - this.posArr[0].y1));
        this.posArr[1].y2 = this.posArr[0].y1;


        //调整二号洞坐标
        this.posArr[2].hx = this.posArr[0].hx + 2 * holdDist_X;
        this.posArr[2].hy = this.posArr[0].hy;

        this.posArr[2].x1 = this.posArr[0].x1 + edge_X + 2 * hold_R + edge_X;
        this.posArr[2].y1 = this.posArr[0].y1;

        this.posArr[2].x2 = this.posArr[0].x2 + edge_LongX;
        this.posArr[2].y2 = this.posArr[0].y2;

        //调整三号洞坐标
        this.posArr[3].hx = this.posArr[0].hx;
        this.posArr[3].hy = this.posArr[0].hy + holdDist_Y;

        this.posArr[3].x1 = this.posArr[0].x2;
        this.posArr[3].y1 = this.posArr[0].y1 + edge_Y;

        this.posArr[3].x2 = this.posArr[0].x1;
        this.posArr[3].y2 = this.posArr[0].y1 + edge_LongY;

        //调整四号洞坐标
        this.posArr[4].hx = this.posArr[1].hx;
        this.posArr[4].hy = this.posArr[3].hy + middleDeviation;

        this.posArr[4].x1 = this.posArr[1].x1;
        this.posArr[4].y1 = this.posArr[3].y2;

        this.posArr[4].x2 = this.posArr[1].x2;
        this.posArr[4].y2 = this.posArr[3].y2;


        //调整五号洞坐标
        this.posArr[5].hx = this.posArr[2].hx;
        this.posArr[5].hy = this.posArr[3].hy;

        this.posArr[5].x1 = this.posArr[2].x2;
        this.posArr[5].y1 = this.posArr[3].y1;

        this.posArr[5].x2 = this.posArr[2].x1;
        this.posArr[5].y2 = this.posArr[3].y2;

    }
    private RotatingCoordinateSystem(radian: number, x: number, y: number) {
        var x1: number = 0;
        var y1: number = 0;
        x1 = x * Math.cos(radian) - y * Math.sin(radian);
        y1 = x * Math.sin(radian) + y * Math.cos(radian);
        var pos = new Array(2);
        pos[0] = x1;
        pos[1] = y1;
        return pos;
    }


    private Brokenline1(px: number, py: number) {
        for (var i: number = 0; i < 6; i++) {
            var _hx: number = this.posArr[i].hx;
            var _hy: number = this.posArr[i].hy;
            var dx = px - _hx;
            var dy = py - _hx;
            var dust2 = Math.sqrt(dx * dx + dy * dy);
            if (dust2 > this.holeR + this._r) {
                var whiteBall_x = this.curBall.nextX;
                var whiteBall_y = this.curBall.nextY;
                var distWhite = Math.sqrt((px - whiteBall_x) * (px - whiteBall_x) + (py - whiteBall_y) * (py - whiteBall_y));


                //判断是否碰到四周的直线球案
                if (this.EdgeTesting(px, py) == 4 || this.HypotenuseDown0(px, py) == 1 || this.HypotenuseUp3(px, py) == 1) {
                    var cosAngle = (whiteBall_x - px) / distWhite;
                    var sinAngle = (py - whiteBall_y) / distWhite;
                    var _pos2_x = 2 * cosAngle * 0.7;
                    var _pos2_y = 2 * sinAngle;
                    this.CollisionDetection(px, py, _pos2_x, _pos2_y);
                }
                if (this.EdgeTesting(px, py) == 2 || this.HypotenuseDown2(px, py) == 1 || this.HypotenuseUp5(px, py) == 1) {
                    sinAngle = (px - whiteBall_x) / distWhite;
                    cosAngle = (py - whiteBall_y) / distWhite;
                    _pos2_x = -2 * sinAngle * 0.7;
                    _pos2_y = 2 * cosAngle;
                    this.CollisionDetection(px, py, _pos2_x, _pos2_y);
                }
                if (this.EdgeTesting(px, py) == 1 || this.HypotenuseRight0(px, py) == 1 || this.HypotenuseLeft2(px, py) == 1) {
                    sinAngle = (px - whiteBall_x) / distWhite;
                    cosAngle = (py - whiteBall_y) / distWhite;
                    _pos2_x = 2 * sinAngle;
                    _pos2_y = -2 * cosAngle * 0.7;
                    this.CollisionDetection(px, py, _pos2_x, _pos2_y);
                }
                if (this.EdgeTesting(px, py) == 3 || this.HypotenuseRight3(px, py) == 1 || this.HypotenuseLeft5(px, py) == 1) {
                    sinAngle = (px - whiteBall_x) / distWhite;
                    cosAngle = (py - whiteBall_y) / distWhite;
                    _pos2_x = 2 * sinAngle;
                    _pos2_y = -2 * cosAngle * 0.7;
                    this.CollisionDetection(px, py, _pos2_x, _pos2_y);
                }
                //
                //
                //判断是否碰到四周的斜边
                //正在斜边的运动轨迹中px，py的运动轨迹由圆弧和直线组成



                //零号洞右边斜边三号洞右边斜边
                if (this.HypotenuseRight0(px, py) == 2) {
                    var rotateAngle = this.GetAngle(this.trapezoid_H, this.trapezoid_Long);
                    var pos1 = new Array(2);
                    var pos2 = new Array(2);
                    var pos3 = new Array(2);
                    pos2 = this.ClockwiseRotateCoordinateSystem(px, py, rotateAngle);
                    pos1 = this.ClockwiseRotateCoordinateSystem(whiteBall_x, whiteBall_y, rotateAngle);

                    // var includedAngle = this.GetAngle(pos2[1] - pos1[1], pos2[0] - pos1[0]);
                    // _pos2_x = -2 * Math.cos(includedAngle);
                    // _pos2_y = 2 * Math.sin(includedAngle) * 0.7;
                    //  pos3 = this.Anti_clockwiseRotateCoordinateSystem(_pos2_x, _pos2_y, rotateAngle);


                    distWhite = Math.sqrt((pos2[0] - pos1[0]) * (pos2[0] - pos1[0]) + (pos2[1] - pos1[1]) * (pos2[1] - pos1[1]));
                    sinAngle = (pos2[0] - pos1[0]) / distWhite;
                    cosAngle = (pos2[1] - pos1[1]) / distWhite;
                    _pos2_x = -2 * sinAngle;
                    _pos2_y = 2 * cosAngle * 0.7;
                    _pos2_x += pos2[0];
                    _pos2_y += pos2[1];
                    pos3 = this.Anti_clockwiseRotateCoordinateSystem(_pos2_x, _pos2_y, rotateAngle);
                    //  this.CollisionDetection(px, py, _pos2_x, _pos2_y);
                    this.CollisionDetection(px, py, pos3[0] - px, pos3[1] - py);
                }
                if (this.HypotenuseRight3(px, py) == 2) {
                    rotateAngle = this.GetAngle(this.trapezoid_H, this.trapezoid_Long);
                    pos1 = new Array(2);
                    pos2 = new Array(2);
                    pos3 = new Array(2);
                    pos2 = this.ClockwiseRotateCoordinateSystem(px, py, rotateAngle);
                    pos1 = this.ClockwiseRotateCoordinateSystem(whiteBall_x, whiteBall_y, rotateAngle);
                    var includedAngle = this.GetAngle(pos2[1] - pos1[1], pos2[0] - pos1[0]);
                    _pos2_x = -2 * Math.cos(includedAngle);
                    _pos2_y = 2 * Math.sin(includedAngle) * 0.7;
                    pos3 = this.Anti_clockwiseRotateCoordinateSystem(_pos2_x, _pos2_y, rotateAngle);
                    this.CollisionDetection(px, py, pos3[0], pos3[1]);
                }

                //零号洞下边斜边二号洞下边斜边
                if (this.HypotenuseDown0(px, py) == 2) {
                    rotateAngle = this.GetAngle(this.trapezoid_H, this.trapezoid_Long);
                    pos1 = new Array(2);
                    pos2 = new Array(2);
                    pos3 = new Array(2);
                    pos2 = this.ClockwiseRotateCoordinateSystem(px, py, rotateAngle);
                    pos1 = this.ClockwiseRotateCoordinateSystem(whiteBall_x, whiteBall_y, rotateAngle);
                    includedAngle = this.GetAngle(pos2[1] - pos1[1], pos2[0] - pos1[0]);
                    _pos2_x = 2 * Math.cos(includedAngle) * 0.7;
                    _pos2_y = -2 * Math.sin(includedAngle);
                    pos3 = this.Anti_clockwiseRotateCoordinateSystem(_pos2_x, _pos2_y, rotateAngle);
                    this.CollisionDetection(px, py, pos3[0], pos3[1]);
                }
                if (this.HypotenuseDown2(px, py) == 2) {
                    rotateAngle = this.GetAngle(this.trapezoid_H, this.trapezoid_Long);
                    pos1 = new Array(2);
                    pos2 = new Array(2);
                    pos3 = new Array(2);
                    pos2 = this.ClockwiseRotateCoordinateSystem(px, py, rotateAngle);
                    pos1 = this.ClockwiseRotateCoordinateSystem(whiteBall_x, whiteBall_y, rotateAngle);
                    includedAngle = this.GetAngle(pos2[1] - pos1[1], pos2[0] - pos1[0]);
                    _pos2_x = 2 * Math.cos(includedAngle) * 0.7;
                    _pos2_y = -2 * Math.sin(includedAngle);
                    pos3 = this.Anti_clockwiseRotateCoordinateSystem(_pos2_x, _pos2_y, rotateAngle);
                    this.CollisionDetection(px, py, pos3[0], pos3[1]);
                }




                //三号洞上边斜边和五号洞上边斜边
                if (this.HypotenuseUp3(px, py) == 2) {
                    rotateAngle = this.GetAngle(this.trapezoid_H, this.trapezoid_Long);
                    pos1 = new Array(2);
                    pos2 = new Array(2);
                    pos3 = new Array(2);
                    pos2 = this.ClockwiseRotateCoordinateSystem(px, py, rotateAngle);
                    pos1 = this.ClockwiseRotateCoordinateSystem(whiteBall_x, whiteBall_y, rotateAngle);
                    includedAngle = this.GetAngle(pos2[1] - pos1[1], pos2[0] - pos1[0]);
                    _pos2_x = -2 * Math.cos(includedAngle) * 0.7;
                    _pos2_y = 2 * Math.sin(includedAngle);
                    pos3 = this.Anti_clockwiseRotateCoordinateSystem(_pos2_x, _pos2_y, rotateAngle);
                    this.CollisionDetection(px, py, pos3[0], pos3[1]);
                }
                if (this.HypotenuseUp5(px, py) == 2) {
                    rotateAngle = this.GetAngle(this.trapezoid_H, this.trapezoid_Long);
                    pos1 = new Array(2);
                    pos2 = new Array(2);
                    pos3 = new Array(2);
                    pos2 = this.ClockwiseRotateCoordinateSystem(px, py, rotateAngle);
                    pos1 = this.ClockwiseRotateCoordinateSystem(whiteBall_x, whiteBall_y, rotateAngle);
                    includedAngle = this.GetAngle(pos2[1] - pos1[1], pos2[0] - pos1[0]);
                    _pos2_x = -2 * Math.cos(includedAngle) * 0.7;
                    _pos2_y = 2 * Math.sin(includedAngle);
                    pos3 = this.Anti_clockwiseRotateCoordinateSystem(_pos2_x, _pos2_y, rotateAngle);
                    this.CollisionDetection(px, py, pos3[0], pos3[1]);
                }



                //二号洞的左边斜边和五号洞的左边斜边
                if (this.HypotenuseLeft2(px, py) == 2) {
                    rotateAngle = this.GetAngle(this.trapezoid_H, this.trapezoid_Long);
                    pos1 = new Array(2);
                    pos2 = new Array(2);
                    pos3 = new Array(2);
                    pos2 = this.ClockwiseRotateCoordinateSystem(px, py, rotateAngle);
                    pos1 = this.ClockwiseRotateCoordinateSystem(whiteBall_x, whiteBall_y, rotateAngle);
                    includedAngle = this.GetAngle(pos2[1] - pos1[1], pos2[0] - pos1[0]);
                    _pos2_x = 2 * Math.cos(includedAngle);
                    _pos2_y = - 2 * Math.sin(includedAngle) * 0.7;
                    pos3 = this.Anti_clockwiseRotateCoordinateSystem(_pos2_x, _pos2_y, rotateAngle);
                    this.CollisionDetection(px, py, pos3[0], pos3[1]);
                }
                if (this.HypotenuseLeft5(px, py) == 2) {
                    rotateAngle = this.GetAngle(this.trapezoid_H, this.trapezoid_Long);
                    pos1 = new Array(2);
                    pos2 = new Array(2);
                    pos3 = new Array(2);
                    pos2 = this.ClockwiseRotateCoordinateSystem(px, py, rotateAngle);
                    pos1 = this.ClockwiseRotateCoordinateSystem(whiteBall_x, whiteBall_y, rotateAngle);
                    includedAngle = this.GetAngle(pos2[1] - pos1[1], pos2[0] - pos1[0]);
                    _pos2_x = 2 * Math.cos(includedAngle);
                    _pos2_y = -2 * Math.sin(includedAngle) * 0.7;
                    pos3 = this.Anti_clockwiseRotateCoordinateSystem(_pos2_x, _pos2_y, rotateAngle);
                    this.CollisionDetection(px, py, pos3[0], pos3[1]);
                }



                //一号洞左边斜边和四号洞左边斜边
                if (this.HypotenuseLeft1(px, py) == 2) {
                    rotateAngle = this.GetAngle(this.trapezoid_H, this.trapezoid_Middle);
                    pos1 = new Array(2);
                    pos2 = new Array(2);
                    pos3 = new Array(2);
                    pos2 = this.ClockwiseRotateCoordinateSystem(px, py, rotateAngle);
                    pos1 = this.ClockwiseRotateCoordinateSystem(whiteBall_x, whiteBall_y, rotateAngle);



                    distWhite = Math.sqrt((pos2[0] - pos1[0]) * (pos2[0] - pos1[0]) + (pos2[1] - pos1[1]) * (pos2[1] - pos1[1]));
                    sinAngle = (pos2[0] - pos1[0]) / distWhite;
                    cosAngle = (pos2[1] - pos1[1]) / distWhite;
                    _pos2_x = 2 * sinAngle;
                    _pos2_y = 2 * cosAngle * 0.7;
                    _pos2_x += pos2[0];
                    _pos2_y += pos2[1];
                    pos3 = this.Anti_clockwiseRotateCoordinateSystem(_pos2_x, _pos2_y, rotateAngle);
                    this.CollisionDetection(px, py, pos3[0] - px, pos3[1] - py);
                }
                if (this.HypotenuseLeft4(px, py) == 2) {
                    rotateAngle = this.GetAngle(this.trapezoid_H, this.trapezoid_Middle);
                    pos1 = new Array(2);
                    pos2 = new Array(2);
                    pos3 = new Array(2);
                    pos2 = this.ClockwiseRotateCoordinateSystem(px, py, rotateAngle);
                    pos1 = this.ClockwiseRotateCoordinateSystem(whiteBall_x, whiteBall_y, rotateAngle);
                    includedAngle = this.GetAngle(pos2[1] - pos1[1], pos2[0] - pos1[0]);
                    _pos2_x = 2 * Math.cos(includedAngle);
                    _pos2_y = -2 * Math.sin(includedAngle) * 0.7;
                    pos3 = this.Anti_clockwiseRotateCoordinateSystem(_pos2_x, _pos2_y, rotateAngle);
                    this.CollisionDetection(px, py, pos3[0], pos3[1]);
                }

                //一号洞的右边斜边和四号洞右边斜边
                if (this.HypotenuseRight1(px, py) == 2) {
                    rotateAngle = this.GetAngle(this.trapezoid_H, this.trapezoid_Middle);
                    pos1 = new Array(2);
                    pos2 = new Array(2);
                    pos3 = new Array(2);
                    pos2 = this.ClockwiseRotateCoordinateSystem(px, py, rotateAngle);
                    pos1 = this.ClockwiseRotateCoordinateSystem(whiteBall_x, whiteBall_y, rotateAngle);
                    distWhite = Math.sqrt((pos2[0] - pos1[0]) * (pos2[0] - pos1[0]) + (pos2[1] - pos1[1]) * (pos2[1] - pos1[1]));
                    sinAngle = (pos2[0] - pos1[0]) / distWhite;
                    cosAngle = (pos2[1] - pos1[1]) / distWhite;
                    _pos2_x = 2 * sinAngle;
                    _pos2_y = -2 * cosAngle * 0.7;
                    _pos2_x += pos2[0];
                    _pos2_y += pos2[1];
                    pos3 = this.Anti_clockwiseRotateCoordinateSystem(_pos2_x, _pos2_y, rotateAngle);
                    this.CollisionDetection(px, py, pos3[0] - px, pos3[1] - py);
                }
                if (this.HypotenuseRight4(px, py) == 2) {
                    rotateAngle = this.GetAngle(this.trapezoid_H, this.trapezoid_Middle);
                    pos1 = new Array(2);
                    pos2 = new Array(2);
                    pos3 = new Array(2);
                    pos2 = this.ClockwiseRotateCoordinateSystem(px, py, rotateAngle);
                    pos1 = this.ClockwiseRotateCoordinateSystem(whiteBall_x, whiteBall_y, rotateAngle);
                    includedAngle = this.GetAngle(pos2[1] - pos1[1], pos2[0] - pos1[0]);
                    _pos2_x = -2 * Math.cos(includedAngle);
                    _pos2_y = 2 * Math.sin(includedAngle) * 0.7;
                    pos3 = this.Anti_clockwiseRotateCoordinateSystem(_pos2_x, _pos2_y, rotateAngle);
                    this.CollisionDetection(px, py, pos3[0], pos3[1]);
                }
            }
        }
    }
    /**
      * which 1：代表传入的x3是x坐标返回一个Y坐标，2：代表传入的X3是y坐标返回的是一个x坐标
      */
    private FirstOrderFunction(x1: number, y1: number, x2: number, y2: number, translation: number, x3: number, which: number) {
        var a: number = 0;
        var b: number = 0;
        a = (y1 - y2) / (x1 - x2);
        b = y1 - a * x1;
        b += translation;
        var y3: number = 0;
        if (which == 1) {
            y3 = a * x3 + b;
            return y3;
        }
        else if (which == 2) {
            y3 = (x3 - b) / a;
            return y3;
        }
        else {
            console.log("FirstOrderFunction输入有误！")
            return null;
        }
    }

    private GetHypotenuseNewPos(Height: number, Length: number, x: number, y: number) {
        var tanAngel = Height / Length;
        var angel = Math.atan(tanAngel);
        var x1 = this._r * Math.cos(angel);
        var y1 = this._r * Math.sin(angel);
        var length = new Array(2);
        length[0] = x1;
        length[1] = y1;
        return length;
    }

    private ganpoint: egret.Point;
    private belowenergy: eui.Image;
    /**最大力量 (能量条最大高度) */
    private MaxPower: number = 400;
    /**击球控制 */
    private addGanEvt() {
        this.StrengthArm.touchEnabled = false;
        this.energy.touchEnabled = false;
        this.belowenergy.visible = false;
        this.belowenergy.touchEnabled = false;
        this.energy.height = 0;
        this.long = 0;

        this.UpdateLiduLabel();
        var rectSA = new egret.Rectangle(0, 0, this.StrengthArm.width, 380);
        this.StrengthArm.mask = rectSA;
        this.belowenergy.y = this.energy.height + 48;
        // this.StrengthArm.mask.x;
        // this.StrengthArm.mask.width;
        // this.StrengthArm.mask.height;
        // this.StrengthArm.mask.y;
        this.lidudi.addEventListener(egret.TouchEvent.TOUCH_BEGIN, e => {
            this.LastY = e.stageY;
            this.ganpoint = new egret.Point(this.ganImg.x, this.ganImg.y);
            this.Aimer.touchEnabled = false;
            this.slip.touchEnabled = false;
            this.MyRange.touchEnabled = false;
        }, this);




        //拉动
        this.lidudi.addEventListener(egret.TouchEvent.TOUCH_MOVE, e => {

            if (this.isOwnGame && (this.isBaiqiu == 0) && !this.isMove) {
                var c = e.stageY - this.LastY;

                //修改位置移动
                this.energy.height += c;
                this.long = this.energy.height;
                this.belowenergy.y = this.energy.height + 48;

                if (this.long < 30) {//大于最小值
                    this.belowenergy.visible = false;
                }
                else if (this.long > this.MaxPower - 30) {//小于最大值

                    this.belowenergy.visible = false;
                }
                else {//显示范围
                    this.belowenergy.visible = true;
                }



                var isneedmove: boolean = true;
                if (this.long < 2) {//最低

                    this.energy.height = 0;
                    this.long = 0;

                    isneedmove = false;
                }

                if (this.long > this.MaxPower - 2) {//最高

                    this.energy.height = this.MaxPower;
                    this.long = this.MaxPower;

                    isneedmove = false;
                }
                this.LastY = e.stageY;
                this.UpdateLiduLabel();

                let tw = egret.Tween.get(this.ganImg);

                // tw.to({ x: this.ganpoint.x, y: this.ganpoint.y })

                if (isneedmove) {
                    var oldx: number = this.ganImg.x;
                    var oldy: number = this.ganImg.y;
                    //球下一帧的移动坐标
                    var dx: number = this.curBall.nextX - oldx;
                    var dy: number = this.curBall.nextY - oldy;
                    //球的弧度（反映球的移动方向,画布坐标系）
                    var angle: number = Math.atan2(dy, dx);
                    var sin: number = Math.sin(angle);
                    var cos: number = Math.cos(angle);
                    var pos0: egret.Point = new egret.Point(0, 0);
                    pos0.x -= c;
                    var pos0F: any = this.rotateR(pos0.x, pos0.y, sin, cos, false);
                    var newOldx = oldx + pos0F.x;
                    var newOldy = oldy + pos0F.y;
                    tw.to({ x: newOldx, y: newOldy });
                    this.LastY = e.stageY;
                }


            }
        }, this);
        //归位
        function e() {
            // this.StrengthArm.y = -150;
            TableUI.Instance().energy.height = 0;
            TableUI.Instance().endFunc();
            this.UpdateLiduLabel();
            this.Aimer.touchEnabled = true;
            this.slip.touchEnabled = true;
            // this.MyRange.touchEnabled = true;
            // this.belowenergy.visible = false;
        };
        this.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE, e, this);
        this.addEventListener(egret.TouchEvent.TOUCH_CANCEL, e, this);
        this.addEventListener(egret.TouchEvent.TOUCH_END, e, this);//ok
        // this.addEventListener(egret.TouchEvent.TOUCH_ROLL_OUT, e, this);
        // this.addEventListener(egret.TouchEvent.TOUCH_ROLL_OVER, e, this);
    }

    /**更新力量显示 */
    private UpdateLiduLabel(): void {
        if (this.long < 0) this.long = 0;
        if (this.long > this.MaxPower) this.long = this.MaxPower;
        var t = parseInt((this.long * 100 / this.MaxPower).toString());
        this.liduLabel.text = "" + t + "";
    }

    //给球加灯光特效
    private AddLightToBall(ball: NewBall) {
        var dragonbonesData = RES.getRes("light3");
        var textureData = RES.getRes("light2");
        var texture = RES.getRes("light4_png");
        var dragonbonesFactory: dragonBones.EgretFactory = new dragonBones.EgretFactory();
        dragonbonesFactory.addDragonBonesData(dragonBones.DataParser.parseDragonBonesData(dragonbonesData));
        dragonbonesFactory.addTextureAtlas(new dragonBones.EgretTextureAtlas(texture, textureData));
        var armature: dragonBones.Armature = dragonbonesFactory.buildArmature("armatureName");
        this.addChild(armature.display);
        armature.display.x = ball.nextX;
        armature.display.y = ball.nextY;
        dragonBones.WorldClock.clock.add(armature);
        armature.animation.gotoAndPlay("zq_guang_001a", -1, -1, 0);
        this.lightArr.push(armature);
        this.setGanOver(armature.display);
    }

    /**错误消息弹出 */
    public errorMsgPopup(msg: string) {
        this.addChild(this.errorMsgMain);
        this.errorMsgMain.errorMsgShow(msg);
    }
    /**改变状态(根据状态进行操作) 1线后自由球 2自由球 3击球 */
    public changeType(type) {
        this.nextOperation = type;
        switch (this.nextOperation) {
            case 1:
                //摆球
                this.isOwnGame = true;
                this.isBaiqiu = 1;
                break;
            case 2:
                //自由球
                this.isOwnGame = true;
                this.isBaiqiu = 2;
                break;
            case 3:
                //击球
                this.isOwnGame = true;
                break;
        }
        this.nextOperation = 0;
    }

    /**显示某个进球 */
    public showBall(num: number): void {
        if (num > 16 || num < 1) return;
        //联网模式下显示进黑8
        if (num == 8) {
            if (this.isLianxi == 2) {
                if (false) { }//判断那个玩家的击球
                //玩家1打进的
                this.smallGroup.$children[7].alpha = 0;
                //玩家2打进的
                this.bigGroup.$children[7].alpha = 0;
            }
            return;
        }
        num--;
        //显示指定球
        this.ballImgArr[num].alpha = 1;
        this.ballImgArr[num].visible = true;
        this.ballImgArr[num].source = "dark";
        // this.ballImgArr[num].width = 43;
        // this.ballImgArr[num].height = 43;
        // this.ballImgArr[num].x += 5;
        // this.ballImgArr[num].y += 5;
    }

    //初始化显示进球
    private InitShowBall(): void {
        var ballsource = ["1s", "2s", "3s", "4s", "5s", "6s", "7s", "8s", "9s", "10s", "11s", "12s", "13s", "14s", "15s", "8s"];
        this.ballImgArr = [this.ball1, this.ball2, this.ball3, this.ball4, this.ball5, this.ball6, this.ball7, this.ball8, this.ball9, this.ball10, this.ball11, this.ball12, this.ball13, this.ball14, this.ball15, this.ball16];

        this.bigGroup.visible = false;
        this.smallGroup.visible = false;


        this.bigGroup.x = this.leftGroupPos.x;
        this.bigGroup.y = this.leftGroupPos.y;
        this.bigGroup.alpha = 1;
        this.smallGroup.x = this.rightGroupPos.x;
        this.smallGroup.y = this.rightGroupPos.y;
        this.smallGroup.alpha = 1;
        this.ball8.visible = false;
        this.ball16.visible = false;
        //隐藏全部球
        for (var i = 0; i < this.bigGroup.$children.length; i++) {
            this.bigGroup.$children[i].alpha = 1;
            this.smallGroup.$children[i].alpha = 1;
        }
        for (var u = 0; u < this.ballImgArr.length; u++) {//重置位置
            this.ballImgArr[u].source = ballsource[u];
            this.ballImgArr[u].width = 52;
            this.ballImgArr[u].height = 52;
            this.ballImgArr[u].y = this.bigGroup.y - 23;
        }


        for (var m = 0; m < this.ballImgArr.length; m++) {//位置
            if (m < 8) {
                this.ballImgArr[m].x = 0 + m * 40;//全色正序
            } else {
                this.ballImgArr[m].x = 0 + (14 - m) * 40 + 40;//花色逆序
            }
        }

        this.ball8.x = this.ball1.x;
        this.ball16.x = this.ball9.x;
    }
    //隐藏进球显示
    private HideShowBall(): void {
        if (!this.bigGroup || !this.smallGroup) return;
        this.bigGroup.visible = false;
        this.smallGroup.visible = false;
    }
    /**
     * r是圆的半径angle是指圆弧的弧度,pos1是指知道的其中一个坐标参数，which   1：代表pos1是相求的值域中的最小值2：代表pos1是想求的值域中的最大值
     * 求圆心运动轨迹中圆弧轨迹的的值域
     */
    private CircularRange(r: number, angle: number, pos1: number, which: number) {
        var pos = new Array(2);
        if (which == 1) {
            pos[0] = pos1;
            pos[1] = pos1 + r * Math.sin(angle);
            return pos;
        }
        else if (which == 2) {
            pos[0] = pos1 - r * Math.sin(angle);
            pos[1] = pos1;
            return pos;
        }
        else {
            console.log("CircularRange_X方法输入有误！")
            return null;
        }
    }
    /**
 * a，b是函数圆的圆心坐标，r是圆的半径，x是圆周上的一个坐标值，which指代的是想要获取那个Y坐标 以Y轴正方向为标准  1：代表圆心上的y坐标2：代表圆心下的y坐标
 * 以x轴正方向为标准3：代表圆心右边的X坐标   4：代表圆心左边的X坐标
 * 求一个圆的函数中圆周上Y的坐标
 */
    private EquationOfCircle(a: number, b: number, r: number, pos1: number, which: number) {
        var pos2: number = 0;
        if (which == 1) {
            pos2 = Math.sqrt(r * r - (pos1 - a) * (pos1 - a)) + b;

            //  console.log("NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN");
            //  console.log("r:",r,"x:",x,"a:",a,"b:",b);
            //  console.log("NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN");

            return pos2;
        }
        else if (which == 2) {
            pos2 = b - Math.sqrt(r * r - (pos1 - a) * (pos1 - a))
            return pos2;
        }
        else if (which == 3) {
            pos2 = a + Math.sqrt(r * r - (pos1 - b) * (pos1 - b));
            return pos2;
        }
        else if (which == 4) {
            pos2 = a - Math.sqrt(r * r - (pos1 - b) * (pos1 - b));
            //    console.log("NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN");
            //    console.log("r:",r,"pos1:",pos1,"a:",a,"b:",b);
            //   console.log("NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN");
            return pos2;
        }
        else {
            console.log("EquationOfCircle方法输入有误！！");
            return null;
        }
    }
    /**
    * 求梯形斜边的弧度
    */
    private GetTrapezoidAngle(Height: number, Length: number) {
        var tanAngel = Height / Length;
        var angel = Math.atan(tanAngel);

        return angel;
    }

    /**显示收到的的表情 1109 */
    public ShowFace(n: any): void {
        var emoj: string = "";
        switch (n) {
            case 1:
                emoj = "02-b";
                break;
            case 2:
                emoj = "03-a";
                break;
            case 3:
                emoj = "04-a";
                break;
            case 4:
                emoj = "09-b";
                break;
            default:
                console.log("unknow type ", n);
                break;
        }
        this.p2b.source = emoj;
        this.p2b.visible = true;
        this.p2b.alpha = 1;

        egret.Tween.removeTweens(this.p2b);
        let tw = Tween.get(this.p2b);
        tw.to({ "scaleX": 1.2, "scaleY": 1.2 }, 200);
        tw.to({ "scaleX": 1, "scaleY": 1 }, 200);
        tw.wait(2000);
        tw.to({ "alpha": 0 }, 1000);

        /**
         * 02-b  生气
         * 03-a  伤心
         * 04-a  滑稽
         * 09-b  真棒
         */
    }



    /**显示发送的表情 */
    public ShowMyFace(n: any): void {
        var emoj: string = "";
        egret.Tween.removeTweens(this.p1b);
        this.p1b.source = "";
        this.p1b.alpha = 0;
        switch (n) {
            case 1:
                emoj = "02-b";
                break;
            case 2:
                emoj = "03-a";
                break;
            case 3:
                emoj = "04-a";
                break;
            case 4:
                emoj = "09-b";
                break;
        }
        this.p1b.source = emoj;
        this.p1b.visible = true;
        this.p1b.alpha = 1;
        let tw = Tween.get(this.p1b);
        tw.to({ "scaleX": 1.2, "scaleY": 1.2 }, 200);
        tw.to({ "scaleX": 1, "scaleY": 1 }, 200);
        tw.wait(2000);
        tw.to({ "alpha": 0 }, 1000);

        /**
         * 02-b  生气
         * 03-a  伤心
         * 04-a  滑稽
         * 09-b  真棒
         */
    }
    /**
     * 返回值： 1：上边，2：右边 3：下边 4：左边
     */
    private EdgeTesting(px: number, py: number) {
        if (px < (this.posArr[0].x3 + this._r) && py >= this.posArr[0].y3 && py <= this.posArr[3].y3) {//
            return 4
        }
        if (px > (this.posArr[2].x4 - this._r) && py >= this.posArr[2].y4 && py <= this.posArr[5].y4) {//
            return 2;
        }
        if ((py < this.posArr[0].y4 + this._r && px >= this.posArr[0].x4 && px <= this.posArr[1].x4) || (py < this.posArr[0].y4 + this._r && px >= this.posArr[1].x3 && px <= this.posArr[2].x3)) {
            return 1;
        }
        if ((py > this.posArr[3].y4 - this._r && px >= this.posArr[0].x4 && px <= this.posArr[1].x4) || (py > this.posArr[3].y4 - this._r && px >= this.posArr[4].x3 && px <= this.posArr[5].x3)) {
            return 3;
        }
        return false;
    }
    /**
     * 0号洞右边斜边判定条件 
     * 返回值 1：斜边区域的圆弧段
     * 2：斜边区域的直线段
     */

    private HypotenuseRight0(px, py) {
        var angle_Trapezoid = this.GetAngle(this.trapezoid_H, this.trapezoid_Long);//获得斜边的弧度制
        var pos_X = new Array(2);//储存X的值域的变量
        var pos_Y = new Array(2);//储存Y的值域的变量
        // console.log(angle_Trapezoid);
        pos_X = this.CircularRange(this._r, angle_Trapezoid, this.posArr[0].x4, 2);
        //  console.log(pos_X[0],pos_X[1])
        //判断圆弧轨迹的碰撞
        if (px >= pos_X[0] && px <= pos_X[1]) {
            var Circular_Y1 = this.EquationOfCircle(this.posArr[0].x4, this.posArr[0].y4, this._r, px, 1);
            var Circular_Y2 = this.EquationOfCircle(this.posArr[3].x4, this.posArr[3].y4, this._r, px, 2);
            // console.log("x的值域",pos_X[0],pos_X[1]);
            // console.log("圆周上y的值",Circular_Y);
            // console.log("py",py);
            if (py <= Circular_Y1) {
                // console.log("222222222222222222222");
                // console.log("px",px);
                // console.log("py",py);
                // console.log("firstCollision",Circular_Y)
                // console.log("222222222222222222222");
                return 1;
            }

        }
        //判断斜边区域直线运动轨迹的碰撞
        if (px <= pos_X[0]) {
            //获得圆心运动轨迹的一次函数上关于px的Y值
            var firstOrderFunction_Y1 = this.FirstOrderFunction(this.posArr[0].x1, this.posArr[0].y1, this.posArr[0].x4, this.posArr[0].y4, this._r / Math.cos(angle_Trapezoid), px, 1);
            // console.log("px",px);
            // console.log("py",py);
            // console.log("firstCollision",firstOrderFunction_Y)
            var firstOrderFunction_Y2 = this.FirstOrderFunction(this.posArr[3].x2, this.posArr[3].y2, this.posArr[3].x4, this.posArr[3].y4, -this._r / Math.cos(angle_Trapezoid), px, 1);
            if (py <= firstOrderFunction_Y1) {
                this.ballY = firstOrderFunction_Y1;
                this.ballX = this.FirstOrderFunction(this.posArr[0].x1, this.posArr[0].y1, this.posArr[0].x4, this.posArr[0].y4, this._r / Math.cos(angle_Trapezoid), py, 2);
                // console.log("11111111111111111111");
                // console.log("px",px);
                // console.log("py",py);
                // console.log("firstCollision",firstOrderFunction_Y)
                // console.log("11111111111111111111");
                return 2;
            }

        }
        return false;
    }
    /**
     * 3号洞右边斜边判定条件 
     * 返回值 1：斜边区域的圆弧段
     * 2：斜边区域的直线段
     */
    private HypotenuseRight3(px, py) {
        var angle_Trapezoid = this.GetAngle(this.trapezoid_H, this.trapezoid_Long);//获得斜边的弧度制
        var pos_X = new Array(2);//储存X的值域的变量
        var pos_Y = new Array(2);//储存Y的值域的变量
        // console.log(angle_Trapezoid);
        pos_X = this.CircularRange(this._r, angle_Trapezoid, this.posArr[0].x4, 2);
        //  console.log(pos_X[0],pos_X[1])
        //判断圆弧轨迹的碰撞
        if (px >= pos_X[0] && px <= pos_X[1]) {
            var Circular_Y1 = this.EquationOfCircle(this.posArr[0].x4, this.posArr[0].y4, this._r, px, 1);
            var Circular_Y2 = this.EquationOfCircle(this.posArr[3].x4, this.posArr[3].y4, this._r, px, 2);
            // console.log("x的值域",pos_X[0],pos_X[1]);
            // console.log("圆周上y的值",Circular_Y);
            // console.log("py",py);

            if (py >= Circular_Y2) {
                return 1;
            }
        }
        //判断斜边区域直线运动轨迹的碰撞
        if (px <= pos_X[0]) {
            //获得圆心运动轨迹的一次函数上关于px的Y值
            var firstOrderFunction_Y1 = this.FirstOrderFunction(this.posArr[0].x1, this.posArr[0].y1, this.posArr[0].x4, this.posArr[0].y4, this._r / Math.cos(angle_Trapezoid), px, 1);
            var firstOrderFunction_Y2 = this.FirstOrderFunction(this.posArr[3].x2, this.posArr[3].y2, this.posArr[3].x4, this.posArr[3].y4, -this._r / Math.cos(angle_Trapezoid), px, 1);

            if (py >= firstOrderFunction_Y2) {
                return 2;
            }
        }
        return false;
    }
    /**
     * 3号洞上边斜边判定条件 
     * 返回值 1：斜边区域的圆弧段
     * 2：斜边区域的直线段
     */
    private HypotenuseUp3(px, py) {
        //三号洞上边斜边和五号洞上边斜边
        var angle_Trapezoid = this.GetAngle(this.trapezoid_H, this.trapezoid_Long);//获得斜边的弧度制
        var pos_X = new Array(2);//储存X的值域的变量
        var pos_Y = new Array(2);//储存Y的值域的变量
        pos_Y = this.CircularRange(this._r, angle_Trapezoid, this.posArr[3].y3, 1);
        //判断圆弧轨迹的碰撞
        if (py >= pos_Y[0] && py <= pos_Y[1]) {
            var Circular_X1 = this.EquationOfCircle(this.posArr[3].x3, this.posArr[3].y3, this._r, py, 3);
            var Circular_X2 = this.EquationOfCircle(this.posArr[5].x4, this.posArr[5].y4, this._r, py, 4);
            //  console.log("y的值域",pos_Y[0],pos_Y[1]);
            //  console.log("圆周上y的值",Circular_X);
            //  console.log("py",py);
            //  console.log("px",px);
            if (px <= Circular_X1) {
                return 1;
            }

        }
        //判断斜边区域直线运动轨迹的碰撞
        if (py >= pos_Y[1]) {
            //获得圆心运动轨迹的一次函数
            var firstOrderFunction_X1 = this.FirstOrderFunction(this.posArr[3].x1, this.posArr[3].y1, this.posArr[3].x3, this.posArr[3].y3, this._r / Math.sin(angle_Trapezoid), py, 2);
            var firstOrderFunction_X2 = this.FirstOrderFunction(this.posArr[5].x1, this.posArr[5].y1, this.posArr[5].x4, this.posArr[5].y4, this._r / Math.sin(angle_Trapezoid), py, 2)
            if (px <= firstOrderFunction_X1) {
                return 2;
            }

        }
        return false;
    }
    /**
     * 5号洞上边斜边判定条件 
     * 返回值 1：斜边区域的圆弧段
     * 2：斜边区域的直线段
     */
    private HypotenuseUp5(px, py) {
        //三号洞上边斜边和五号洞上边斜边
        var angle_Trapezoid = this.GetAngle(this.trapezoid_H, this.trapezoid_Long);//获得斜边的弧度制
        var pos_X = new Array(2);//储存X的值域的变量
        var pos_Y = new Array(2);//储存Y的值域的变量
        pos_Y = this.CircularRange(this._r, angle_Trapezoid, this.posArr[5].y4, 1);
        //判断圆弧轨迹的碰撞
        if (py >= pos_Y[0] && py <= pos_Y[1]) {
            var Circular_X1 = this.EquationOfCircle(this.posArr[3].x3, this.posArr[3].y3, this._r, py, 3);
            var Circular_X2 = this.EquationOfCircle(this.posArr[5].x4, this.posArr[5].y4, this._r, py, 4);
            //  console.log("y的值域",pos_Y[0],pos_Y[1]);
            //  console.log("圆周上y的值",Circular_X);
            //  console.log("py",py);
            //  console.log("px",px);

            if (px >= Circular_X2) {
                return 1;
            }
        }
        //判断斜边区域直线运动轨迹的碰撞
        if (py >= pos_Y[1]) {
            //获得圆心运动轨迹的一次函数
            var firstOrderFunction_X1 = this.FirstOrderFunction(this.posArr[3].x1, this.posArr[3].y1, this.posArr[3].x3, this.posArr[3].y3, this._r / Math.sin(angle_Trapezoid), py, 2);
            var firstOrderFunction_X2 = this.FirstOrderFunction(this.posArr[5].x1, this.posArr[5].y1, this.posArr[5].x4, this.posArr[5].y4, this._r / Math.sin(angle_Trapezoid), py, 2)

            if (px >= firstOrderFunction_X2) {
                return 2;
            }
        }
        return false;
    }
    /**
     * 0号洞下边斜边判定条件 
     * 返回值 1：斜边区域的圆弧段
     * 2：斜边区域的直线段
     */
    private HypotenuseDown0(px, py) {
        //三号洞上边斜边和五号洞上边斜边
        var angle_Trapezoid = this.GetAngle(this.trapezoid_H, this.trapezoid_Long);//获得斜边的弧度制
        var pos_X = new Array(2);//储存X的值域的变量
        var pos_Y = new Array(2);//储存Y的值域的变量
        //零号洞下边斜边二号洞下边斜边




        // var angle_Trapezoid=this.GetTrapezoidAngle(this.trapezoid_H,this.trapezoid_Long);//获得斜边的弧度制
        pos_Y = this.CircularRange(this._r, angle_Trapezoid, this.posArr[0].y3, 2);
        //判断圆弧轨迹的碰撞
        if (py >= pos_Y[0] && py <= pos_Y[1]) {
            var Circular_X1 = this.EquationOfCircle(this.posArr[0].x3, this.posArr[0].y3, this._r, py, 3);
            var Circular_X2 = this.EquationOfCircle(this.posArr[2].x4, this.posArr[2].y4, this._r, py, 4);
            //  console.log("y的值域",pos_Y[0],pos_Y[1]);
            //  console.log("圆周上y的值",Circular_X2);
            //  console.log("py",py);
            //  console.log("px",px);
            if (px <= Circular_X1) {
                return 1;
            }

        }
        //判断斜边区域直线运动轨迹的碰撞
        if (py <= pos_Y[0]) {
            //获得圆心运动轨迹的一次函数
            var firstOrderFunction_X1 = this.FirstOrderFunction(this.posArr[0].x2, this.posArr[0].y2, this.posArr[0].x3, this.posArr[0].y3, -this._r / Math.sin(angle_Trapezoid), py, 2);
            var firstOrderFunction_X2 = this.FirstOrderFunction(this.posArr[2].x2, this.posArr[2].y2, this.posArr[2].x4, this.posArr[2].y4, -this._r / Math.sin(angle_Trapezoid), py, 2)
            if (px <= firstOrderFunction_X1) {
                return 2;
            }

        }
        return false;
    }
    /**
     * 2号洞下边斜边判定条件 
     * 返回值 1：斜边区域的圆弧段
     * 2：斜边区域的直线段
     */
    private HypotenuseDown2(px, py) {
        //三号洞上边斜边和五号洞上边斜边
        var angle_Trapezoid = this.GetAngle(this.trapezoid_H, this.trapezoid_Long);//获得斜边的弧度制
        var pos_X = new Array(2);//储存X的值域的变量
        var pos_Y = new Array(2);//储存Y的值域的变量
        //零号洞下边斜边二号洞下边斜边




        // var angle_Trapezoid=this.GetTrapezoidAngle(this.trapezoid_H,this.trapezoid_Long);//获得斜边的弧度制
        pos_Y = this.CircularRange(this._r, angle_Trapezoid, this.posArr[0].y3, 2);
        //判断圆弧轨迹的碰撞
        if (py >= pos_Y[0] && py <= pos_Y[1]) {
            var Circular_X1 = this.EquationOfCircle(this.posArr[0].x3, this.posArr[0].y3, this._r, py, 3);
            var Circular_X2 = this.EquationOfCircle(this.posArr[2].x4, this.posArr[2].y4, this._r, py, 4);
            //  console.log("y的值域",pos_Y[0],pos_Y[1]);
            //  console.log("圆周上y的值",Circular_X2);
            //  console.log("py",py);
            //  console.log("px",px);

            if (px >= Circular_X2) {
                return 1;
            }
        }
        //判断斜边区域直线运动轨迹的碰撞
        if (py <= pos_Y[0]) {
            //获得圆心运动轨迹的一次函数
            var firstOrderFunction_X1 = this.FirstOrderFunction(this.posArr[0].x2, this.posArr[0].y2, this.posArr[0].x3, this.posArr[0].y3, -this._r / Math.sin(angle_Trapezoid), py, 2);
            var firstOrderFunction_X2 = this.FirstOrderFunction(this.posArr[2].x2, this.posArr[2].y2, this.posArr[2].x4, this.posArr[2].y4, -this._r / Math.sin(angle_Trapezoid), py, 2)

            if (px >= firstOrderFunction_X2) {
                return 2;
            }
        }
        return false;
    }
    /**
     * 2号洞左边斜边判定条件 
     * 返回值 1：斜边区域的圆弧段
     * 2：斜边区域的直线段
     */
    private HypotenuseLeft2(px, py) {
        //三号洞上边斜边和五号洞上边斜边
        var angle_Trapezoid = this.GetAngle(this.trapezoid_H, this.trapezoid_Long);//获得斜边的弧度制
        var pos_X = new Array(2);//储存X的值域的变量
        var pos_Y = new Array(2);//储存Y的值域的变量
        //二号洞的左边斜边和五号洞的左边斜边
        pos_X = this.CircularRange(this._r, angle_Trapezoid, this.posArr[2].x3, 1);
        //判断圆弧轨迹的碰撞
        if (px >= pos_X[0] && px <= pos_X[1]) {
            var Circular_Y1 = this.EquationOfCircle(this.posArr[2].x3, this.posArr[2].y3, this._r, px, 1);
            var Circular_Y2 = this.EquationOfCircle(this.posArr[5].x3, this.posArr[5].y3, this._r, px, 2);
            // console.log("y的值域", pos_Y[0], pos_Y[1]);
            //console.log("圆周上y的值", Circular_Y1);
            //console.log("py", py);
            // console.log("px", px);
            if (py <= Circular_Y1) {
                return 1;
            }

        }

        //判断斜边区域直线运动轨迹的碰撞
        if (px >= pos_X[1]) {
            //获得圆心运动轨迹的一次函数上关于px的Y值
            var firstOrderFunction_Y1 = this.FirstOrderFunction(this.posArr[2].x1, this.posArr[2].y1, this.posArr[2].x3, this.posArr[2].y3, this._r / Math.cos(angle_Trapezoid), px, 1);
            var firstOrderFunction_Y2 = this.FirstOrderFunction(this.posArr[5].x2, this.posArr[5].y2, this.posArr[5].x3, this.posArr[5].y3, -this._r / Math.cos(angle_Trapezoid), px, 1);
            // console.log("px:", px);
            // console.log("py:", py);
            //console.log("firstOrderFunction_Y1:", firstOrderFunction_Y1);
            if (py <= firstOrderFunction_Y1) {
                return 2;
            }

        }
        return false;
    }
    /**
     * 5号洞左边斜边判定条件 
     * 返回值 1：斜边区域的圆弧段
     * 2：斜边区域的直线段
     */
    private HypotenuseLeft5(px, py) {
        //三号洞上边斜边和五号洞上边斜边
        var angle_Trapezoid = this.GetAngle(this.trapezoid_H, this.trapezoid_Long);//获得斜边的弧度制
        var pos_X = new Array(2);//储存X的值域的变量
        var pos_Y = new Array(2);//储存Y的值域的变量
        //二号洞的左边斜边和五号洞的左边斜边
        pos_X = this.CircularRange(this._r, angle_Trapezoid, this.posArr[2].x3, 1);
        //判断圆弧轨迹的碰撞
        if (px >= pos_X[0] && px <= pos_X[1]) {
            var Circular_Y1 = this.EquationOfCircle(this.posArr[2].x3, this.posArr[2].y3, this._r, px, 1);
            var Circular_Y2 = this.EquationOfCircle(this.posArr[5].x3, this.posArr[5].y3, this._r, px, 2);
            // console.log("y的值域", pos_Y[0], pos_Y[1]);
            //console.log("圆周上y的值", Circular_Y1);
            //console.log("py", py);
            // console.log("px", px);

            if (py >= Circular_Y2) {
                return 1;
            }
        }

        //判断斜边区域直线运动轨迹的碰撞
        if (px >= pos_X[1]) {
            //获得圆心运动轨迹的一次函数上关于px的Y值
            var firstOrderFunction_Y1 = this.FirstOrderFunction(this.posArr[2].x1, this.posArr[2].y1, this.posArr[2].x3, this.posArr[2].y3, this._r / Math.cos(angle_Trapezoid), px, 1);
            var firstOrderFunction_Y2 = this.FirstOrderFunction(this.posArr[5].x2, this.posArr[5].y2, this.posArr[5].x3, this.posArr[5].y3, -this._r / Math.cos(angle_Trapezoid), px, 1);
            // console.log("px:", px);
            // console.log("py:", py);
            //console.log("firstOrderFunction_Y1:", firstOrderFunction_Y1);

            if (py >= firstOrderFunction_Y2) {
                return 2;
            }
        }
        return false;
    }
    /**
     * 1号洞左边斜边判定条件 
     * 返回值 1：斜边区域的圆弧段
     * 2：斜边区域的直线段
     */
    private HypotenuseLeft1(px, py) {
        var pos_X = new Array(2);//储存X的值域的变量
        var pos_Y = new Array(2);//储存Y的值域的变量
        var angle_Trapezoid1 = this.GetAngle(this.trapezoid_H, this.trapezoid_Middle);//获得斜边的弧度制
        pos_X = this.CircularRange(this._r, angle_Trapezoid1, this.posArr[1].x4, 1);
        if (px >= pos_X[0] && px <= pos_X[1]) {
            var Circular_Y1 = this.EquationOfCircle(this.posArr[1].x4, this.posArr[1].y4, this._r, px, 1);
            var Circular_Y2 = this.EquationOfCircle(this.posArr[4].x4, this.posArr[4].y4, this._r, px, 2);
            if (py <= Circular_Y1) {
                return 1;
            }

        }
        //判断斜边区域直线运动轨迹的碰撞
        if (px >= pos_X[1]) {
            //获得圆心运动轨迹的一次函数上关于px的Y值
            var firstOrderFunction_Y1 = this.FirstOrderFunction(this.posArr[1].x1, this.posArr[1].y1, this.posArr[1].x4, this.posArr[1].y4, this._r / Math.cos(angle_Trapezoid1), px, 1);
            var firstOrderFunction_Y2 = this.FirstOrderFunction(this.posArr[4].x1, this.posArr[4].y1, this.posArr[4].x4, this.posArr[4].y4, -this._r / Math.cos(angle_Trapezoid1), px, 1);
            if (py <= firstOrderFunction_Y1) {
                // console.log("11111111111111111111");
                // console.log("px",px);
                // console.log("py",py);
                // console.log("firstCollision",firstOrderFunction_Y)
                // console.log("11111111111111111111");
                return 2;
            }

        }
        return false;
    }
    /**
     * 4号洞左边斜边判定条件 
     * 返回值 1：斜边区域的圆弧段
     * 2：斜边区域的直线段
     */
    private HypotenuseLeft4(px, py) {
        var pos_X = new Array(2);//储存X的值域的变量
        var pos_Y = new Array(2);//储存Y的值域的变量
        var angle_Trapezoid1 = this.GetAngle(this.trapezoid_H, this.trapezoid_Middle);//获得斜边的弧度制
        pos_X = this.CircularRange(this._r, angle_Trapezoid1, this.posArr[1].x4, 1);
        if (px >= pos_X[0] && px <= pos_X[1]) {
            var Circular_Y1 = this.EquationOfCircle(this.posArr[1].x4, this.posArr[1].y4, this._r, px, 1);
            var Circular_Y2 = this.EquationOfCircle(this.posArr[4].x4, this.posArr[4].y4, this._r, px, 2);

            if (py >= Circular_Y2) {
                return 1;
            }
        }
        //判断斜边区域直线运动轨迹的碰撞
        if (px >= pos_X[1]) {
            //获得圆心运动轨迹的一次函数上关于px的Y值
            var firstOrderFunction_Y1 = this.FirstOrderFunction(this.posArr[1].x1, this.posArr[1].y1, this.posArr[1].x4, this.posArr[1].y4, this._r / Math.cos(angle_Trapezoid1), px, 1);
            var firstOrderFunction_Y2 = this.FirstOrderFunction(this.posArr[4].x1, this.posArr[4].y1, this.posArr[4].x4, this.posArr[4].y4, -this._r / Math.cos(angle_Trapezoid1), px, 1);

            if (py >= firstOrderFunction_Y2) {
                return 2;
            }
        }
        return false;
    }
    /**
     * 1号洞右边斜边判定条件 
     * 返回值 1：斜边区域的圆弧段
     * 2：斜边区域的直线段
     */
    private HypotenuseRight1(px, py) {
        var pos_X = new Array(2);//储存X的值域的变量
        var pos_Y = new Array(2);//储存Y的值域的变量
        var angle_Trapezoid1 = this.GetAngle(this.trapezoid_H, this.trapezoid_Middle);//获得斜边的弧度制

        pos_X = this.CircularRange(this._r, angle_Trapezoid1, this.posArr[1].x3, 2);
        if (px >= pos_X[0] && px <= pos_X[1]) {
            var Circular_Y1 = this.EquationOfCircle(this.posArr[1].x3, this.posArr[1].y3, this._r, px, 1);
            var Circular_Y2 = this.EquationOfCircle(this.posArr[4].x3, this.posArr[4].y3, this._r, px, 2);
            if (py <= Circular_Y1) {
                py = Circular_Y1;
                px = this.EquationOfCircle(this.posArr[4].x3, this.posArr[4].y3, this._r, py, 4);
                this.ballX = px;
                this.ballY = py;
                return 1;
            }
        }
        //判断斜边区域直线运动轨迹的碰撞
        if (px <= pos_X[0]) {
            //获得圆心运动轨迹的一次函数上关于px的Y值
            var firstOrderFunction_Y1 = this.FirstOrderFunction(this.posArr[1].x2, this.posArr[1].y2, this.posArr[1].x3, this.posArr[1].y3, this._r / Math.cos(angle_Trapezoid1), px, 1);
            var firstOrderFunction_Y2 = this.FirstOrderFunction(this.posArr[4].x2, this.posArr[4].y2, this.posArr[4].x3, this.posArr[4].y3, -this._r / Math.cos(angle_Trapezoid1), px, 1);
            if (py <= firstOrderFunction_Y1) {
                // console.log("11111111111111111111");
                // console.log("px",px);
                // console.log("py",py);
                // console.log("firstCollision",firstOrderFunction_Y)
                // console.log("11111111111111111111");
                return 2;
            }
        }
        return false;
    }
    /**
     * 4号洞右边斜边判定条件 
     * 返回值 1：斜边区域的圆弧段
     * 2：斜边区域的直线段
     */
    private HypotenuseRight4(px, py) {
        var pos_X = new Array(2);//储存X的值域的变量
        var pos_Y = new Array(2);//储存Y的值域的变量
        var angle_Trapezoid1 = this.GetAngle(this.trapezoid_H, this.trapezoid_Middle);//获得斜边的弧度制
        //一号洞的右边斜边和四号洞右边斜边
        pos_X = this.CircularRange(this._r, angle_Trapezoid1, this.posArr[1].x3, 2);
        if (px >= pos_X[0] && px <= pos_X[1]) {
            var Circular_Y1 = this.EquationOfCircle(this.posArr[1].x3, this.posArr[1].y3, this._r, px, 1);
            var Circular_Y2 = this.EquationOfCircle(this.posArr[4].x3, this.posArr[4].y3, this._r, px, 2);

            if (py >= Circular_Y2) {
                return 1;
            }
        }
        //判断斜边区域直线运动轨迹的碰撞
        if (px <= pos_X[0]) {
            //获得圆心运动轨迹的一次函数上关于px的Y值
            var firstOrderFunction_Y1 = this.FirstOrderFunction(this.posArr[1].x2, this.posArr[1].y2, this.posArr[1].x3, this.posArr[1].y3, this._r / Math.cos(angle_Trapezoid1), px, 1);
            var firstOrderFunction_Y2 = this.FirstOrderFunction(this.posArr[4].x2, this.posArr[4].y2, this.posArr[4].x3, this.posArr[4].y3, -this._r / Math.cos(angle_Trapezoid1), px, 1);

            if (py >= firstOrderFunction_Y2) {
                return 2;
            }
        }
        return false;
    }
    /**
     * 逆时针旋转坐标系得到当前xy在旋转后的坐标系下的xy
     */
    private Anti_clockwiseRotateCoordinateSystem(x: number, y: number, angel: number) {
        var x1 = x * Math.cos(angel) + y * Math.sin(angel);
        var y1 = y * Math.cos(angel) - x * Math.sin(angel);
        var pos = new Array(2);
        pos[0] = x1;
        pos[1] = y1;
        return pos;
    }
    /**
     * 顺时针旋转坐标系得到当前xy在旋转后的坐标系下的xy
     */
    private ClockwiseRotateCoordinateSystem(x: number, y: number, angel: number) {
        var x1 = x * Math.cos(angel) - y * Math.sin(angel);
        var y1 = y * Math.cos(angel) + x * Math.sin(angel);
        var pos = new Array(2);
        pos[0] = x1;
        pos[1] = y1;
        return pos;
    }
    /**
    * 求梯形斜边的弧度
    */
    private GetAngle(Height: number, Length: number) {
        var tanAngel = Height / Length;
        var angel = Math.atan(tanAngel);

        return angel;
    }
    private setSubline1() {
        var v: number = 2;

        var vx: number = 0;
        var vy: number = 0;

        //计算球的速度
        if (this.angleNum == 1) {
            vx = v * Math.sin(this.angleSpeed);
            vy = -v * Math.cos(this.angleSpeed);
        }
        else if (this.angleNum == 2) {
            vx = v * Math.cos(this.angleSpeed);
            vy = v * Math.sin(this.angleSpeed);
        }
        else if (this.angleNum == 3) {
            vx = v * Math.sin(this.angleSpeed);
            vy = -v * Math.cos(this.angleSpeed);
        }
        else if (this.angleNum == 4) {
            vx = -v * Math.cos(this.angleSpeed);
            vy = v * Math.sin(this.angleSpeed);
        }

        // this.shp1.graphics.clear();
        // this.shp2.graphics.clear();
        // this.shp3.graphics.clear();
        // this.shp4.graphics.clear();
        // this.shp5.graphics.clear();

        var px: number = this.curBall.nextX;
        var py: number = this.curBall.nextY;

        let pos = new Point(px, py);
        let velocity = new Point(vx, vy);
        if (!this.CollisionDetection1(pos, velocity)) {
            this.CollisionDetection1(pos, velocity, false);
        }
    }
    private CollisionDetection1(pos: Point, veloctity: Point, isfirst: boolean = true): boolean {
        var isImpactWithBall: boolean = false;
        var isImpactWithLeft: boolean = false;
        var isImpactWithRight: boolean = false;
        var isImpactWithTop: boolean = false;
        var isImpactWithBottom: boolean = false;
        var isEnterHole: boolean = false;
        var px = pos.x;
        var py = pos.y;
        var vx = veloctity.x;
        var vy = veloctity.y;
        var orignrX = px;
        var orignrY = py;
        //每一步计算划线的下一点
        for (var i: number = 0; i < 1500; i++) { //以一个单位的大小进行移动 每个点判断是否碰到东西 碰到则退出
            px += vx;
            py += vy;
            //遍历所有的球
            for (var j: number = 0; j < this.ballArr.length; j++) { //遍历所有彩球
                var ballA: NewBall = this.ballArr[j];
                if (ballA.name == "cur") {
                    continue;
                }
                var dx: number = ballA.nextX - px;//px是白球的坐标 nextX是其他球的坐标   (i倍的)vx
                var dy: number = ballA.nextY - py; // (i倍的)vy
                var dist: number = Math.sqrt(dx * dx + dy * dy);//两球之间的距离  （勾股定理求斜边）


                //距离<球的半径，代表碰到球了

                if (dist <= 2 * this._r) {//小于直径碰撞 （撞到了彩球）
                    isImpactWithBall = true;
                    var a1: any = this.rotationCoord(px, py, this.huadongAngle);
                    var a2: any = this.rotationCoord(ballA.nextX, ballA.nextY, this.huadongAngle);

                    var dx0: number = a1.x - a2.x;
                    var dy0: number = a1.y - a2.y;
                    var dist0: number = Math.sqrt(dx0 * dx0 + dy0 * dy0);
                    var asd: number = Math.abs(dx0 / dist0);
                    var num: number = dy0 / Math.abs(dy0);

                    //计算两点之间的X与Y轴的距离计算出来两点之间的斜率角度
                    var angle: number = Math.atan2(dy, dx);
                    var sin: number = Math.sin(angle);
                    var cos: number = Math.cos(angle);
                    var pos1: egret.Point = this.rotateR(dx, dy, sin, cos, true);

                    pos1.x += 70 * asd;

                    var pos2: egret.Point = new egret.Point(0, num * (this._r + 50 * (1 - asd)));

                    var pos3: egret.Point = new egret.Point(0, num * this._r);

                    var pos1F: any = this.rotateR(pos1.x, pos1.y, sin, cos, false);

                    var pos2F: any = this.rotateR(pos2.x, pos2.y, sin, cos, false);

                    var pos3F: any = this.rotateR(pos3.x, pos3.y, sin, cos, false);

                    this.shp1.graphics.lineStyle(1.5, 0xFFFFFF);//白球第一条瞄准线
                    this.shp1.graphics.moveTo(orignrX, orignrY);
                    this.shp1.graphics.lineTo(px, py);
                    this.shp1.graphics.endFill();


                    //已弃用
                    this.shp3.graphics.lineStyle(0.5, 0xFFFFFF);//红线  0xFF0000 （碰到的彩球走向）
                    this.shp3.graphics.moveTo(ballA.nextX, ballA.nextY);
                    this.shp3.graphics.lineTo(px + pos1F.x, py + pos1F.y);
                    this.shp3.graphics.endFill();

                    this.shp4.graphics.lineStyle(3, 0xFFFFFF);//蓝线  0x0000FF （白球走向）
                    this.shp4.graphics.moveTo(px, py);//起点
                    this.shp4.graphics.lineTo(px + pos2F.x, py + pos2F.y);//终点
                    this.shp4.graphics.endFill();



                    this.shp2.graphics.lineStyle(1.5, 0xFFFFFF);
                    this.shp2.graphics.drawCircle(px, py, this._r - 2);
                    this.shp2.graphics.endFill();
                    this.shp2.graphics.clear();

                    break;
                }
            }
            if (isImpactWithBall) {//撞到了彩球退出1500递增
                break;
            }

            //进洞检测
            for (var i: number = 0; i < 6; i++) {
                var _hx: number = this.posArr[i].hx;
                var _hy: number = this.posArr[i].hy;
                if (px > _hx - this.holeR && px < _hx + this.holeR && py > _hy - this.holeR && py < _hy + this.holeR) {
                    isEnterHole = true;
                    break;
                }
            }

            if (isEnterHole) {
                break;
            }
            isImpactWithLeft = this.CheckLeftDraw(px, py, pos, veloctity);
            if (isImpactWithLeft) {
                break;
            }
            isImpactWithRight = this.CheckRightDraw(px, py, pos, veloctity);
            if (isImpactWithRight) {
                break;
            }
            isImpactWithTop = this.CheckTopDraw(px, py, pos, veloctity);
            if (isImpactWithTop) {
                break;
            }
            isImpactWithBottom = this.CheckBottomDraw(px, py, pos, veloctity);
            if (isImpactWithBottom) {
                break;
            }






        }//1500结束

        if (isImpactWithLeft || isImpactWithRight || isImpactWithTop || isImpactWithBottom) {
            this.shp1.graphics.lineStyle(1.5, 0xFFFFFF);//白球第一条瞄准线
            this.shp1.graphics.moveTo(orignrX, orignrY);
            this.shp1.graphics.lineTo(pos.x, pos.y);
            this.shp1.graphics.endFill();

            if (!isfirst) {
                // this.shp2.graphics.lineStyle(1.5, 0xFFFFFF);
                // this.shp2.graphics.drawCircle(pos.x, pos.y, this._r - 2);
                // this.shp2.graphics.endFill();
            }
            return false;
        }
        if (isImpactWithBall || isEnterHole)
            return true;
        return true;
    }
    public CheckLeftDraw(px: number, py: number, pos: Point, veloctity: Point): boolean {
        let isImpactWithWall: boolean = false;
        let isImpactWithHole: boolean = false;
        pos.x = px;
        pos.y = py;
        // 撞到了左边的墙或者洞
        if (px < this.posArr[0].x1 + this._r) {
            //碰到了左边的墙 
            if ((py < this.posArr[0].y1 && py > this.posArr[1].y1) //下边界
                || (py < this.posArr[1].y2 && py > this.posArr[2].y1)) //上边界
            {
                pos.x = this.posArr[0].x1 + this._r;
                veloctity.x *= this.bounce;
                isImpactWithWall = true;
                console.log("碰到了左边的墙 球的位置 " + pos.x + "," + pos.y + "速度" + veloctity.x + "," + veloctity.y);
            }
            else if (py >= this.posArr[0].y1) {//球碰撞进0号洞
                var dx: number = px - this.posArr[0].x1;
                var dy: number = py - this.posArr[0].y1;
                var dist: number = Math.sqrt(dx * dx + dy * dy);//球和洞的距离
                if (dist < this._r) {
                    this.reboundDraw(pos, veloctity, this.posArr[0].x1, this.posArr[0].y1, this.bounce);
                    console.log("碰到了左边的墙洞0 " + pos.x + "," + pos.y + "速度" + veloctity.x + "," + veloctity.y);
                    isImpactWithHole = true;
                }
            }
            else if (py <= this.posArr[1].y1 && py > this.posArr[1].hy) {//球碰撞进1号洞左边
                var dx: number = px - this.posArr[1].x1;
                var dy: number = py - this.posArr[1].y1;
                var dist: number = Math.sqrt(dx * dx + dy * dy);
                if (dist < this._r) {
                    this.reboundDraw(pos, veloctity, this.posArr[1].x1, this.posArr[1].y1, this.bounce);
                    console.log("碰到了左边的墙洞1左边 " + pos.x + "," + pos.y + "速度" + veloctity.x + "," + veloctity.y);
                    isImpactWithHole = true;
                }
            }
            else if (py >= this.posArr[1].y2 && py < this.posArr[1].hy) {//球碰撞进1号洞右边

                var dx: number = px - this.posArr[1].x2;
                var dy: number = py - this.posArr[1].y2;
                var dist: number = Math.sqrt(dx * dx + dy * dy);
                if (dist < this._r) {
                    this.reboundDraw(pos, veloctity, this.posArr[1].x2, this.posArr[1].y2, this.bounce);
                    console.log("碰到了左边的墙洞1右边 " + pos.x + "," + pos.y + "速度" + veloctity.x + "," + veloctity.y);
                    isImpactWithHole = true;
                }
            }
            else if (py >= this.posArr[2].y1) {//球碰撞进2号洞
                var dx: number = px - this.posArr[2].x1;
                var dy: number = py - this.posArr[2].y1;
                var dist: number = Math.sqrt(dx * dx + dy * dy);
                if (dist < this._r) {

                    this.reboundDraw(pos, veloctity, this.posArr[2].x1, this.posArr[2].y1, this.bounce);
                    console.log("碰到了左边的墙洞0 " + pos.x + "," + pos.y + "速度" + veloctity.x + "," + veloctity.y);
                    isImpactWithHole = true;
                }
            }
        }
        if (isImpactWithHole || isImpactWithWall) {
            return true;
        }
        return false;
    }

    public CheckTopDraw(px: number, py: number, pos: Point, veloctity: Point): boolean {
        let isImpactWithWall: boolean = false;
        let isImpactWithHole: boolean = false;
        pos.x = px;
        pos.y = py;
        if (py < this.posArr[2].y2 + this._r) {
            if (px > this.posArr[2].x1 && px < this.posArr[5].x1) {
                pos.y = this.posArr[2].y2 + this._r;
                veloctity.y *= this.bounce;
                console.log("碰到了上边的墙 球的位置 " + pos.x + "," + pos.y + "速度" + veloctity.x + "," + veloctity.y);
                isImpactWithWall = true;
            }
            if (py <= this.posArr[2].y2) {
                var dx: number = px - this.posArr[2].x2;
                var dy: number = py - this.posArr[2].y2;
                var dist: number = Math.sqrt(dx * dx + dy * dy);
                if (dist < this._r) {
                    this.reboundDraw(pos, veloctity, this.posArr[2].x2, this.posArr[2].y2, this.bounce);
                    isImpactWithHole = true;
                    console.log("碰到了上边的墙洞2 球的位置 " + pos.x + "," + pos.y + "速度" + veloctity.x + "," + veloctity.y);
                }
            }
            if (py >= this.posArr[5].y1) {
                var dx: number = px - this.posArr[5].x1;
                var dy: number = py - this.posArr[5].y1;
                var dist: number = Math.sqrt(dx * dx + dy * dy);
                if (dist < this._r) {
                    this.reboundDraw(pos, veloctity, this.posArr[5].x1, this.posArr[5].y1, this.bounce);
                    isImpactWithHole = true;
                    console.log("碰到了上边的墙洞5 球的位置 " + pos.x + "," + pos.y + "速度" + veloctity.x + "," + veloctity.y);
                }
            }
        }
        if (isImpactWithHole || isImpactWithWall) {
            return true;
        }

        return false;
    }

    public CheckBottomDraw(px: number, py: number, pos: Point, veloctity: Point): boolean {
        let isImpactWithWall: boolean = false;
        let isImpactWithHole: boolean = false;
        pos.x = px;
        pos.y = py;
        if (py > this.posArr[0].y2 - this._r) {
            if (px > this.posArr[0].x2 && px < this.posArr[3].x1) {
                pos.y = this.posArr[0].y2 - this._r;
                veloctity.y *= this.bounce;
                isImpactWithWall = true;
                console.log("碰到了下边的墙 球的位置 " + pos.x + "," + pos.y + "速度" + veloctity.x + "," + veloctity.y);
            }
            if (py <= this.posArr[0].y2) {
                var dx: number = px - this.posArr[0].x2;
                var dy: number = py - this.posArr[0].y2;
                var dist: number = Math.sqrt(dx * dx + dy * dy);
                if (dist < this._r) {
                    this.reboundDraw(pos, veloctity, this.posArr[0].x2, this.posArr[0].y2, this.bounce);
                    isImpactWithHole = true;
                    console.log("碰到了下边的墙 洞0 球的位置 " + pos.x + "," + pos.y + "速度" + veloctity.x + "," + veloctity.y);
                }
            }
            if (py >= this.posArr[3].y1) {
                var dx: number = px - this.posArr[3].x1;
                var dy: number = py - this.posArr[3].y1;
                var dist: number = Math.sqrt(dx * dx + dy * dy);
                if (dist < this._r) {
                    this.reboundDraw(pos, veloctity, this.posArr[3].x1, this.posArr[3].y1, this.bounce);
                    isImpactWithHole = true;
                    console.log("碰到了下边的墙 洞3 球的位置 " + pos.x + "," + pos.y + "速度" + veloctity.x + "," + veloctity.y);
                }
            }
        }
        if (isImpactWithHole || isImpactWithWall) {
            return true;
        }
        return false;
    }

    public CheckRightDraw(px: number, py: number, pos: Point, veloctity: Point): boolean {
        let isImpactWithWall: boolean = false;
        let isImpactWithHole: boolean = false;
        pos.x = px;
        pos.y = py;
        if (px > this.posArr[3].x2 - this._r) {
            if ((py < this.posArr[3].y2 && py > this.posArr[4].y1)
                || (py < this.posArr[4].y2 && py > this.posArr[5].y2)) {
                pos.x = this.posArr[3].x2 - this._r;
                veloctity.x *= this.bounce;
                isImpactWithWall = true;
                console.log("碰到了右边的墙 球的位置 " + pos.x + "," + pos.y + "速度" + veloctity.x + "," + veloctity.y);
            }
            if (py <= this.posArr[3].y2) {
                var dx: number = px - this.posArr[3].x2;
                var dy: number = py - this.posArr[3].y2;
                var dist: number = Math.sqrt(dx * dx + dy * dy);
                if (dist < this._r) {
                    this.reboundDraw(pos, veloctity, this.posArr[3].x2, this.posArr[3].y2, this.bounce);
                    isImpactWithHole = true;
                    console.log("碰到了右边的墙洞3 " + pos.x + "," + pos.y + "速度" + veloctity.x + "," + veloctity.y);
                }

            }
            if (px <= this.posArr[4].y1 && px > this.posArr[4].hy) {
                var dx: number = px - this.posArr[4].x1;
                var dy: number = py - this.posArr[4].y1;
                var dist: number = Math.sqrt(dx * dx + dy * dy);
                if (dist < this._r) {
                    this.reboundDraw(pos, veloctity, this.posArr[4].x1, this.posArr[4].y1, this.bounce);
                    isImpactWithHole = true;
                    console.log("碰到了右边的墙洞4 左" + pos.x + "," + pos.y + "速度" + veloctity.x + "," + veloctity.y);
                }

            }
            if (px >= this.posArr[4].y2 && px < this.posArr[4].hy) {
                var dx: number = px - this.posArr[4].x2;
                var dy: number = py - this.posArr[4].y2;
                var dist: number = Math.sqrt(dx * dx + dy * dy);
                if (dist < this._r) {
                    this.reboundDraw(pos, veloctity, this.posArr[4].x2, this.posArr[4].y2, this.bounce);
                    isImpactWithHole = true;

                }
            }
            if (px >= this.posArr[5].y1) {
                var dx: number = px - this.posArr[5].x1;
                var dy: number = py - this.posArr[5].y1;
                var dist: number = Math.sqrt(dx * dx + dy * dy);
                if (dist < this._r) {
                    this.reboundDraw(pos, veloctity, this.posArr[5].x1, this.posArr[5].y1, this.bounce);
                    isImpactWithHole = true;
                    console.log("碰到了右边的墙洞5" + pos.x + "," + pos.y + "速度" + veloctity.x + "," + veloctity.y);
                }
            }
        }
        if (isImpactWithHole || isImpactWithWall) {
            return true;
        }
        return false;
    }

    private reboundDraw(ballPos: Point, velocity: Point, holePosX: number, holePosY: number, bound: number) {
        if (bound == 0) {
            velocity.x = 0;
            velocity.y = 0;
            return;
        }
        let holePos = new Point(holePosX, holePosY);
        //洞坐标相对球的位置
        let relativeWorldHolePos: Point = Point.sub(holePos, ballPos);
        var angle: number = Math.atan2(relativeWorldHolePos.y, relativeWorldHolePos.y);
        var sin: number = Math.sin(angle);
        var cos: number = Math.cos(angle);

        var localTouchtPos: egret.Point = new egret.Point(0, 0);
        var localHolePos = this.rotateR(relativeWorldHolePos.x, relativeWorldHolePos.y, sin, cos, true);
        localTouchtPos.x = localHolePos.x - this._r - 0.0001;
        var relativeWorldTouchPos: any = this.rotateR(localTouchtPos.x, localTouchtPos.y, sin, cos, false);
        ballPos.x = ballPos.x + relativeWorldTouchPos.x;
        ballPos.y = ballPos.x + relativeWorldTouchPos.x;

        velocity.x = velocity.x * bound;
        velocity.y = velocity.y * bound;

    }
    private checkWalls1(b: NewBall) { //检查6个洞及墙的碰撞
        for (var i: number = 0; i < 6; i++) {
            var _hx: number = this.posArr[i].hx;
            var _hy: number = this.posArr[i].hy;
            if (b.nextX > _hx - this.holeR && b.nextX < _hx + this.holeR && b.nextY > _hy - this.holeR && b.nextY < _hy + this.holeR) {
                var dx: number = b.nextX - _hx;
                var dy: number = b.nextY - _hy;
                var dist: number = Math.sqrt(dx * dx + dy * dy);
                if (dist < this.holeR) {
                    console.log("进球号： " + b.idx);
                    // console.log("进球总数：", this.iii++);
                    if (b.idx != 0) {
                        this.scoreiii += 15; //进彩球得分
                    } else {
                        this.scoreiii -= 10; //进白球减分
                    }
                    // this.scoretext.text = "" + this.scoreiii;//实时更新
                    // var channel: egret.SoundChannel = this.soundrudong.play(0, 1);
                    var v = Math.sqrt(b.vx * b.vx + b.vy * b.vy) / 2;
                    this.PlaySoundWithVolume(v, TableUI.Instance().goalSound);
                    // if (v > 1) v = 1;
                    // //channel.volume = v;

                    // channel.volume = Math.sqrt(b.vx * b.vx + b.vy * b.vy) / 2;

                    b.vx = 0;
                    b.vy = 0;
                    b.isJindong = i;
                }
            }
        }
        //左边
        if (b.nextX < this.posArr[0].x1 + this._r) {
            if (b.nextY < this.posArr[0].y1 && b.nextY > this.posArr[1].y1) {//确认碰撞到0-1号洞上边界
                b.nextX = this.posArr[0].x1 + this._r;
                //var channel: egret.SoundChannel = this.soundzhuangbian.play(0, 1);
                var v = Math.sqrt(b.vx * b.vx + b.vy * b.vy) / 2;
                if (v > 1) v = 1;
                //channel.volume = v;
                b.vx *= this.bounce;
            }
            if (b.nextY < this.posArr[1].y2 && b.nextY > this.posArr[2].y1) {//确认碰撞到1-2号洞上边界
                b.nextX = this.posArr[0].x1 + this._r;
                //var channel: egret.SoundChannel = this.soundzhuangbian.play(0, 1);
                var v = Math.sqrt(b.vx * b.vx + b.vy * b.vy) / 2;
                if (v > 1) v = 1;
                //channel.volume = v;
                b.vx *= this.bounce;
            }
            if (b.nextY >= this.posArr[0].y1) {//球碰撞进0号洞
                var dx: number = b.nextX - this.posArr[0].x1;
                var dy: number = b.nextY - this.posArr[0].y1;
                var dist: number = Math.sqrt(dx * dx + dy * dy);
                if (dist < this._r) {
                    this.rebound(b, this.posArr[0].x1, this.posArr[0].y1, 0.7);
                }
            }
            if (b.nextY <= this.posArr[1].y1 && b.nextY > this.posArr[1].hy) {//球碰撞进1号洞左边

                var dx: number = b.nextX - this.posArr[1].x1;
                var dy: number = b.nextY - this.posArr[1].y1;
                var dist: number = Math.sqrt(dx * dx + dy * dy);
                if (dist < this._r) {
                    this.rebound(b, this.posArr[1].x1, this.posArr[1].y1, 0.7);
                }
            }
            if (b.nextY >= this.posArr[1].y2 && b.nextY < this.posArr[1].hy) {//球碰撞进1号洞右边

                var dx: number = b.nextX - this.posArr[1].x2;
                var dy: number = b.nextY - this.posArr[1].y2;
                var dist: number = Math.sqrt(dx * dx + dy * dy);
                if (dist < this._r) {
                    this.rebound(b, this.posArr[1].x2, this.posArr[1].y2, 0.7);
                }
            }
            if (b.nextY >= this.posArr[2].y1) {//球碰撞进2号洞

                var dx: number = b.nextX - this.posArr[2].x1;
                var dy: number = b.nextY - this.posArr[2].y1;
                var dist: number = Math.sqrt(dx * dx + dy * dy);
                if (dist < this._r) {
                    this.rebound(b, this.posArr[2].x1, this.posArr[2].y1, 0.7);
                }
            }

        }
        //右边
        if (b.nextX > this.posArr[3].x2 - this._r) {
            if (b.nextY < this.posArr[3].y2 && b.nextY > this.posArr[4].y1) {
                b.nextX = this.posArr[3].x2 - this._r;
                //var channel: egret.SoundChannel = this.soundzhuangbian.play(0, 1);
                var v = Math.sqrt(b.vx * b.vx + b.vy * b.vy) / 2;
                if (v > 1) v = 1;
                //channel.volume = v;
                b.vx *= this.bounce;
            }
            if (b.nextY < this.posArr[4].y2 && b.nextY > this.posArr[5].y2) {
                b.nextX = this.posArr[3].x2 - this._r;
                //var channel: egret.SoundChannel = this.soundzhuangbian.play(0, 1);
                var v = Math.sqrt(b.vx * b.vx + b.vy * b.vy) / 2;
                if (v > 1) v = 1;
                //channel.volume = v;
                b.vx *= this.bounce;
            }
            if (b.nextY <= this.posArr[3].y2) {
                var dx: number = b.nextX - this.posArr[3].x2;
                var dy: number = b.nextY - this.posArr[3].y2;
                var dist: number = Math.sqrt(dx * dx + dy * dy);
                if (dist < this._r) {
                    this.rebound(b, this.posArr[3].x2, this.posArr[3].y2, 0.7);
                }
            }
            if (b.nextX <= this.posArr[4].y1 && b.nextX > this.posArr[4].hy) {
                var dx: number = b.nextX - this.posArr[4].x1;
                var dy: number = b.nextY - this.posArr[4].y1;
                var dist: number = Math.sqrt(dx * dx + dy * dy);
                if (dist < this._r) {
                    this.rebound(b, this.posArr[4].x1, this.posArr[4].y1, 0.7);
                }
            }
            if (b.nextX >= this.posArr[4].y2 && b.nextX < this.posArr[4].hy) {
                var dx: number = b.nextX - this.posArr[4].x2;
                var dy: number = b.nextY - this.posArr[4].y2;
                var dist: number = Math.sqrt(dx * dx + dy * dy);
                if (dist < this._r) {
                    this.rebound(b, this.posArr[4].x2, this.posArr[4].y2, 0.7);
                }
            }
            if (b.nextX >= this.posArr[5].y1) {
                var dx: number = b.nextX - this.posArr[5].x1;
                var dy: number = b.nextY - this.posArr[5].y1;
                var dist: number = Math.sqrt(dx * dx + dy * dy);
                if (dist < this._r) {
                    this.rebound(b, this.posArr[5].x1, this.posArr[5].y1, 0.7);
                }
            }
        }
        //上边
        if (b.nextY < this.posArr[2].y2 + this._r) {
            if (b.nextX > this.posArr[2].x1 && b.nextX < this.posArr[5].x1) {
                b.nextY = this.posArr[2].y2 + this._r;

                //var channel: egret.SoundChannel = this.soundzhuangbian.play(0, 1);
                var v = Math.sqrt(b.vx * b.vx + b.vy * b.vy) / 2;
                if (v > 1) v = 1;
                //channel.volume = v;

                b.vy *= this.bounce;
                return false;
            }
            if (b.nextY <= this.posArr[2].y2) {
                var dx: number = b.nextX - this.posArr[2].x2;
                var dy: number = b.nextY - this.posArr[2].y2;
                var dist: number = Math.sqrt(dx * dx + dy * dy);
                if (dist < this._r) {
                    this.rebound(b, this.posArr[2].x2, this.posArr[2].y2, 0.7);
                }
            }
            if (b.nextY >= this.posArr[5].y1) {
                var dx: number = b.nextX - this.posArr[5].x1;
                var dy: number = b.nextY - this.posArr[5].y1;
                var dist: number = Math.sqrt(dx * dx + dy * dy);
                if (dist < this._r) {
                    this.rebound(b, this.posArr[5].x1, this.posArr[5].y1, 0.7);
                }
            }
        }
        //下边
        if (b.nextY > this.posArr[0].y2 - this._r) {
            if (b.nextX > this.posArr[0].x2 && b.nextX < this.posArr[3].x1) {
                b.nextY = this.posArr[0].y2 - this._r;

                //var channel: egret.SoundChannel = this.soundzhuangbian.play(0, 1);
                var v = Math.sqrt(b.vx * b.vx + b.vy * b.vy) / 2;
                if (v > 1) v = 1;
                //channel.volume = v;

                b.vy *= this.bounce;
                return false;
            }
            if (b.nextY <= this.posArr[0].y2) {
                var dx: number = b.nextX - this.posArr[0].x2;
                var dy: number = b.nextY - this.posArr[0].y2;
                var dist: number = Math.sqrt(dx * dx + dy * dy);
                if (dist < this._r) {
                    this.rebound(b, this.posArr[0].x2, this.posArr[0].y2, 0.7);
                }
            }
            if (b.nextY >= this.posArr[3].y1) {
                var dx: number = b.nextX - this.posArr[3].x1;
                var dy: number = b.nextY - this.posArr[3].y1;
                var dist: number = Math.sqrt(dx * dx + dy * dy);
                if (dist < this._r) {
                    this.rebound(b, this.posArr[3].x1, this.posArr[3].y1, 0.7);
                }
            }
        }
    }


    /**断线重连信息显示 */
    public breakLineMsgShow(msg: string) {
        this.breakLineShow.visible = true;
        this.breakLineShow.text = msg;
    }


    /**清除所有瞄准线 灯光*/
    public ClearAllLine() {


        this.clearAlllinpic();


        //清除瞄准线
        this.shp1.graphics.clear();
        this.shp2.graphics.clear();
        this.shp2_2.graphics.clear();
        this.shp3.graphics.clear();
        this.shp4.graphics.clear();
        this.shp5.graphics.clear();
        //停止灯光特效
        for (var i: number = 0; i < this.lightArr.length; i++) {
            if (this.lightArr[i]) {
                this.lightArr[i].animation.gotoAndStop("zq_guang_001a", 0);
                this.removeChild(this.lightArr[i].display);
                dragonBones.WorldClock.clock.remove(this.lightArr[i]);
            }
        }
        //清空灯光特效组
        this.lightArr = [];

        //清空灯光图片
        for (var y = 0; y < this.lightImageArr.length; y++) {
            if (this.lightImageArr[y]) {
                this.removeChild(this.lightImageArr[y]);
            }
        }
        this.lightImageArr = [];
    }

    /**仅清除瞄准线 */
    private ClearSubline() {
        //清除瞄准线
        this.shp1.graphics.clear();
        this.shp2.graphics.clear();
        this.shp2_2.graphics.clear();
        this.shp3.graphics.clear();
        this.shp4.graphics.clear();
        this.shp5.graphics.clear();
    }

    /**联网拖动以确定白球位置 */
    public SMmoveWhiteball(e, type) {
        setBaiPos(-100, -100);
        refreshUI();
        if (this.whiteBall == null) {

            this.whiteBall = new eui.Image("whiteBall");
            this.whiteBall.anchorOffsetX = 109 / 2;
            this.whiteBall.anchorOffsetY = 109 / 2;
            this.ganImg.visible = false;
            this.addChild(this.whiteBall);
            this.MyRange.touchEnabled = false;
            // this.whiteBall.addEventListener(egret.TouchEvent.TOUCH_MOVE, this.moveWhiteball, this);

            this.whiteBall.x = (this.posArr[0].x3 + this.posArr[2].x2) / 2;
            this.whiteBall.y = (this.posArr[0].y3 + this.posArr[3].y3) / 2;
            // this.whiteBall.x = 272;
            // this.whiteBall.y = 400;
            this.swapChildren(this.whiteBall, this.promptWord);
            // return;
        }
        var num: number = 0;
        if (type == 1) {
            num = 400 + this._r;//划线
        }
        if (type == 2) {
            num = this.posArr[2].x1;
        }
        if (e.stageX >= this.posArr[0].x1 && e.stageX <= this.posArr[2].x1 && e.stageY >= this.posArr[0].y2 && e.stageY <= this.posArr[3].y1) {
            if (type != 0) {
                if (type == 1) {   //线后自由球
                    if (e.stageX > 400) {//划线  或者碰到球
                        if (this.xIcon == null) {
                            this.xIcon = new eui.Image("forbid");
                            this.xIcon.anchorOffsetX = 109 / 2;
                            this.xIcon.anchorOffsetY = 109 / 2;
                            this.addChild(this.xIcon);
                            // this.xIcon.addEventListener(egret.TouchEvent.TOUCH_MOVE, this.moveWhiteball, this);
                            this.xIcon.touchEnabled = false;
                        }
                        this.xIcon.x = e.stageX;
                        this.xIcon.y = e.stageY;
                    }
                    else {
                        if (this.xIcon && this.xIcon.parent) {
                            this.removeChild(this.xIcon);
                            this.xIcon = null;
                        }
                    }
                    this.whiteBall.x = e.stageX;
                    this.whiteBall.y = e.stageY;
                }
                if (type == 2) {   //自由球
                    if (this.CheckBallCollision(e.stageX, e.stageY)) {
                        if (this.xIcon == null) {
                            this.xIcon = new eui.Image("forbid");
                            this.xIcon.anchorOffsetX = 109 / 2;
                            this.xIcon.anchorOffsetY = 109 / 2;
                            this.addChild(this.xIcon);
                            // this.xIcon.addEventListener(egret.TouchEvent.TOUCH_MOVE, this.moveWhiteball, this);
                            this.xIcon.touchEnabled = false;
                        }
                        this.xIcon.x = e.stageX;
                        this.xIcon.y = e.stageY;
                    }
                    else {
                        if (this.xIcon && this.xIcon.parent) {
                            this.removeChild(this.xIcon);
                            this.xIcon = null;
                        }
                    }
                    this.whiteBall.x = e.stageX;
                    this.whiteBall.y = e.stageY
                }
                // this.getWhiteBallPos(e.stageX, e.stageY);
            }
        }

    }
    /**拖动以确定白球位置 */
    public moveWhiteball(e: egret.TouchEvent) {
        if (this.isLianxi == 1 && this.myLeg) {
            var curTime: number = egret.getTimer();
            if (curTime - this.moveTime > 100) {
                this.moveTime = curTime;
                if (webNetworkMananger.getInstance().isMoving) {
                    webNetworkMananger.getInstance().sendBaiPoint(new egret.Point(e.stageX, e.stageY), this.isBaiqiu);
                }
            }
        }
        this.MyRange.touchEnabled = true;
        this.MyRange.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.giveWhiteBallPos, this);
        var num: number = 0;
        if (this.isBaiqiu == 1) {
            num = 400 + this._r;//划线
        }
        if (this.isBaiqiu == 2) {
            num = this.posArr[2].x1;
        }
        if (e.stageX >= this.posArr[0].x1 && e.stageX <= this.posArr[2].x1 && e.stageY >= this.posArr[0].y2 && e.stageY <= this.posArr[3].y1) {
            if (this.isBaiqiu != 0) {
                if (this.isBaiqiu == 1) {   //线后自由球
                    if (e.stageX > 400) {//划线  或者碰到球
                        if (this.xIcon == null) {
                            this.xIcon = new eui.Image("forbid");
                            this.xIcon.anchorOffsetX = 109 / 2;
                            this.xIcon.anchorOffsetY = 109 / 2;
                            this.addChild(this.xIcon);
                            // this.xIcon.addEventListener(egret.TouchEvent.TOUCH_MOVE, this.moveWhiteball, this);
                            this.xIcon.touchEnabled = false;
                        }
                        this.xIcon.x = e.stageX;
                        this.xIcon.y = e.stageY;
                    }
                    else {
                        if (this.xIcon && this.xIcon.parent) {
                            this.removeChild(this.xIcon);
                            this.xIcon = null;
                        }
                    }
                    this.whiteBall.x = e.stageX;
                    this.whiteBall.y = e.stageY;
                }
                if (this.isBaiqiu == 2) {   //自由球
                    if (this.CheckBallCollision(e.stageX, e.stageY)) {
                        if (this.xIcon == null) {
                            this.xIcon = new eui.Image("forbid");
                            this.xIcon.anchorOffsetX = 109 / 2;
                            this.xIcon.anchorOffsetY = 109 / 2;
                            this.addChild(this.xIcon);
                            // this.xIcon.addEventListener(egret.TouchEvent.TOUCH_MOVE, this.moveWhiteball, this);
                            this.xIcon.touchEnabled = false;
                        }
                        this.xIcon.x = e.stageX;
                        this.xIcon.y = e.stageY;
                    }
                    else {
                        if (this.xIcon && this.xIcon.parent) {
                            this.removeChild(this.xIcon);
                            this.xIcon = null;
                        }
                    }
                    this.whiteBall.x = e.stageX;
                    this.whiteBall.y = e.stageY
                }
                // this.getWhiteBallPos(e.stageX, e.stageY);
            }
        }

    }


    /**显示出可拖动的白球 */
    private showWhiteBall() {
        if (this.isBaiqiu != 0) {
            setBallPos1(-100, -100, 0);//防止穿帮
            refreshUI();
            this.ClearSubline();//清瞄准线
            if (this.whiteBall == null) {
                this.whiteBall = new eui.Image("whiteBall");
                this.whiteBall.anchorOffsetX = 109 / 2;
                this.whiteBall.anchorOffsetY = 109 / 2;
                this.ganImg.visible = false;
                this.addChild(this.whiteBall);
                this.MyRange.touchEnabled = false;
                this.addEventListener(egret.TouchEvent.TOUCH_MOVE, this.moveWhiteball, this);
                // this.whiteBall.addEventListener(egret.TouchEvent.TOUCH_MOVE, this.moveWhiteball, this);

                this.whiteBall.x = (this.posArr[0].x3 + this.posArr[2].x2) / 2;
                this.whiteBall.y = (this.posArr[0].y3 + this.posArr[3].y3) / 2;
                // this.whiteBall.x = 272;
                // this.whiteBall.y = 400;
                this.swapChildren(this.whiteBall, this.promptWord);
            }
        }
    }


    // private whiteBall_X: number;
    // private whiteBall_Y: number;
    // private getWhiteBallPos(x: number, y: number) {
    //     this.whiteBall_X = x;
    //     this.whiteBall_Y = y;
    // }
    private giveWhiteBallPos() {
        // this.beginFunc(this.whiteBall_X, this.whiteBall_Y);
        this.beginFunc();
    }



    private back: eui.Image;
    private Voice: eui.Image;
    private fakevoice: boolean = true;
    /**返回界面 */
    private backMain() {
        this.setChildIndex(this.menu, this.numChildren - 1);
        this.menu.visible = true;
        console.log("Back Button");

    }
    /** 语音及返回控件 */
    private initBackAndVoice() {
        this.quitGame.addEventListener(egret.TouchEvent.TOUCH_TAP, () => {
            this.menu.visible = false;
            this.quitFunc();
            console.log("quit game");
        }, this);
        this.goonGame.addEventListener(egret.TouchEvent.TOUCH_TAP, () => {
            this.menu.visible = false;
            console.log("goon game");
        }, this);

        this.Voice.addEventListener(egret.TouchEvent.TOUCH_TAP, () => {
            // this.fakevoice++;
            // if (this.fakevoice > 1) {
            //     this.fakevoice = 0;
            // }
            if (this.fakevoice) {
                this.fakevoice = false;
                console.log("Microphone on");
                this.Voice.source = "pool_microphone";
            } else {
                this.fakevoice = true;
                this.Voice.source = "pool_microphone_off";
                console.log("Microphone off");
            }
        }, this);
    }
    /**清除“白球” */
    public ClearW() {
        if (this.whiteBall && this.whiteBall.parent) {
            this.removeChild(this.whiteBall);
            this.whiteBall = null;
        }
        if (this.xIcon && this.xIcon.parent) {
            this.removeChild(this.xIcon);
            this.xIcon = null;
        }
        this.isBaiqiu = 0;
        this.removeEventListener(egret.TouchEvent.TOUCH_MOVE, this.moveWhiteball, this);
    }
    /**切换到玩家的操作 */
    public MyRound() {
        this.MyRange.touchEnabled = true;
        this.slipgroup.visible = true;
        this.ld.visible = true;
        this.isOwnGame = true;
    }
    /**非玩家操作 */
    public OppositeRound() {
        this.MyRange.touchEnabled = false;
        this.slipgroup.visible = false;
        this.ld.visible = false;
        this.isOwnGame = false;
    }
    /**隐藏杆 */
    public HideGanImg() {
        this.ganImg.visible = false;
    }

    /**显示杆 */
    public ShowGanImg() {
        this.ganImg.visible = true;
    }
    /**进球音效 */
    private goalSound: egret.Sound[] = [];
    /**击球音效 */
    private shootSound: egret.Sound[] = [];
    /**连进音效 */
    private comboSound: egret.Sound[] = [];
    /**球撞球音效 */
    private ballCrashsSound: egret.Sound[] = [];
    /**Back Ground Music */
    private BGMSound: egret.Sound;
    /**初始化声音资源 */
    private initSoundRES() {
        this.goalSound = RES.getRes("");
        //egret.setTimeout(() => {


        //}, this, 1000);
        this.BGMSound = RES.getRes("pool_bg_mp3");

        var channelBEM: egret.SoundChannel = this.BGMSound.play(0, 0);


        this.shootSound.push(RES.getRes("shoot01_mp3"));
        this.shootSound.push(RES.getRes("shoot02_mp3"));
        this.comboSound.push(RES.getRes("combo1_mp3"));
        this.comboSound.push(RES.getRes("combo2_mp3"));
        this.ballCrashsSound.push(RES.getRes("ballcrash_mp3"));
    }
    /**随机播放音效 传入音量 传入声音组 */
    private PlaySoundWithVolume(volume: number, sound: egret.Sound[]) {
        if (sound == null || sound == undefined) return;
        if (volume > 1)
            volume = 1;
        var p = Math.floor(Math.random() * (sound.length + 1));
        if (p >= sound.length) p = sound.length - 1;
        var channelShoot = sound[p].play(0, 1);
        channelShoot.volume = volume;
    }

    /**小号组第一个变黑八 */
    public ShowBall8() {
        this.ball8.visible = true;
        this.ball8.alpha = 1;
        this.ball8.source = "8s";
        this.ball8.x = this.ball1.x;
    }

    /**大号组第一个变黑八 */
    public ShowBall16() {
        this.ball16.visible = true;
        this.ball16.alpha = 1;
        this.ball16.source = "8s";
        this.ball16.x = this.ball9.x;
    }

    /**给黑八加灯光 */
    public lighttoball8() {
        if (!this.ismeturn()) { return; }
        if (this.seeAboutSurplus(this.myColor, this.ballArr)) { return; }
        var ball: NewBall = this.ballArr[8];
        if (ball == undefined) return;
        if (ball.isJindong == -2) return;
        var dragonbonesData = RES.getRes("light3");
        var textureData = RES.getRes("light2");
        var texture = RES.getRes("light4_png");
        var dragonbonesFactory: dragonBones.EgretFactory = new dragonBones.EgretFactory();
        dragonbonesFactory.addDragonBonesData(dragonBones.DataParser.parseDragonBonesData(dragonbonesData));
        dragonbonesFactory.addTextureAtlas(new dragonBones.EgretTextureAtlas(texture, textureData));
        var armature: dragonBones.Armature = dragonbonesFactory.buildArmature("armatureName");
        this.addChild(armature.display);
        armature.display.x = ball.nextX;
        armature.display.y = ball.nextY;
        dragonBones.WorldClock.clock.add(armature);
        this.lightArr.push(armature);
        this.setGanOver(armature.display);
    }

    /**检查是否与球相交*/
    private CheckBallCollision(mpx: number, mpy: number) {
        for (var j: number = 0; j < this.ballArr.length; j++) {
            var ballA: NewBall = this.ballArr[j];
            if (ballA.name == "cur") {
                continue;
            }
            var dx: number = ballA.nextX - mpx;
            var dy: number = ballA.nextY - mpy;
            var dist: number = Math.sqrt(dx * dx + dy * dy);
            if (dist <= 2 * this._r) {//放到球上了
                return true;
            }
        }
        return false;
    }
    /**是我的回合 联网 AI */
    private ismeturn() {
        if (this.isLianxi == 1) {
            if (webNetworkMananger.getInstance().isMoving) {
                if (this.myLeg) {
                    // console.log("目前是 PVP 我的回合")
                    return true;
                }
                else {
                    // console.log("目前是 PVP 对方回合")
                    return false;
                }
            }
            if (!webNetworkMananger.getInstance().isMoving) {
                if (this.homeServer.nowShoot == -1) {
                    // console.log("目前是 AI mode 我的回合")
                    return true;
                }
                if (this.homeServer.nowShoot == 1) {
                    // console.log("目前是 AI mode 对方回合")
                    return false;
                }
            }
        } else {
            // console.log("目前是 solo 我的回合")
            return true;
        }
    }


    /**根据求终端相对起点的角度 */
    public GetAngel(sx, sy, nx, ny) {
        //起点
        var qx: number = sx;
        var qy: number = sy;
        //终端
        var dx: number = nx;
        var dy: number = ny;
        //距离
        var _a: number = dx - qx;//左右(a>0右)
        var _b: number = dy - qy;//上下(b>0下)
        var _c: number = Math.sqrt((dx - qx) * (dx - qx) + (dy - qy) * (dy - qy));

        var Result = { x: 0, y: 0, rotation: 0, speed: 0, angleNum: 0, huadongAngle: 0, ganLen: 0 };
        //↗
        if (_a >= 0 && _b <= 0) {
            Result.rotation = Math.asin(_a / _c) * 180 / Math.PI - 90;//相对角度
            Result.speed = Math.asin(_a / _c);
            Result.angleNum = 1;
            Result.huadongAngle = Result.speed - Math.PI / 2;
            Result.x = qx - (Result.ganLen) * Math.sin(Math.asin(_a / _c));
            Result.y = qy + (Result.ganLen) * Math.cos(Math.asin(_a / _c));
        }
        //↘
        if (_a > 0 && _b > 0) {
            Result.rotation = (Math.asin(_b / _c)) * 180 / Math.PI;
            Result.speed = Math.asin(_b / _c);
            Result.angleNum = 2;
            Result.huadongAngle = Result.speed;
            Result.x = qx - (Result.ganLen) * Math.cos((Math.asin(_b / _c)));
            Result.y = qy - (Result.ganLen) * Math.sin((Math.asin(_b / _c)));
        }
        //↖
        if (_b < 0 && _a < 0) {
            Result.rotation = Math.asin(_a / _c) * 180 / Math.PI - 90;
            Result.speed = Math.asin(_a / _c);
            Result.angleNum = 3;
            Result.huadongAngle = Result.speed - Math.PI / 2;
            Result.x = qx + (Result.ganLen) * Math.sin(Math.asin(-_a / _c));
            Result.y = qy + (Result.ganLen) * Math.cos(Math.asin(-_a / _c));
        }
        //↙
        if (_a < 0 && _b > 0) {
            Result.rotation = (-(Math.asin(_b / _c) + 90 * Math.PI / 180)) * 180 / Math.PI - 90;
            Result.speed = Math.asin(_b / _c);
            Result.angleNum = 4;
            Result.huadongAngle = Math.PI - Result.speed;
            Result.x = qx + (Result.ganLen) * Math.cos(Math.asin(_b / _c));
            Result.y = qy - (Result.ganLen) * Math.sin(Math.asin(_b / _c));
        }
        return Result;
    }

    /**线 */
    private lin1: eui.Image;
    /**圆 */
    private lin2: eui.Image;
    /**线 */
    private lin3: eui.Image;
    /**线 */
    private lin4: eui.Image;
    /**线 */
    private lin5: eui.Image;

    private linArr: eui.Image[] = [];
    /**初始化瞄准线图片 */
    private initlinpic() {
        this.linArr = [this.lin1, this.lin2, this.lin3, this.lin4, this.lin5]
        var __soupic = ["line_png", "yuan_png", "line_png", "line_png", "line_png"];
        for (var r = 0; r < this.linArr.length; r++) {
            this.linArr[r].source = __soupic[r];
            this.linArr[r].width = 5;
            this.linArr[r].anchorOffsetX = 2.5;
            this.linArr[r].anchorOffsetY = 0;
            // this.linArr[r].visible = false;
        }
    }

    /**清除所有瞄准线(图片) */
    public clearAlllinpic() {
        for (var k = 0; k < this.linArr.length; k++) {
            if (this.linArr[k]) {
                if (this.linArr[k].visible) {
                    this.linArr[k].visible = false;
                }
            }
        }
    }

    /**设置瞄准线图片 */
    private setlinpic(sx, sy, nx, ny, lin: eui.Image) {
        //距离
        var x = sx - nx;
        var y = sy - ny;

        lin.x = sx;
        lin.y = sy;

        // lin.width = 1;

        var lelin1 = Math.sqrt(x * x + y * y);
        lin.height = lelin1;

        lin.source = "line_png";

        if (!lin.parent) {
            this.addChild(lin);
        }

        if (!lin.visible) {
            lin.visible = true;
        }

        if (this.linArr.indexOf(lin) == -1) {
            this.linArr.push(lin);
        }

        //转角
        var result = this.GetAngel(sx, sy, nx, ny);
        lin.rotation = result.rotation - 90;
    }

    /**设置圆圈图片 */
    private setcirpic(x: number, y: number, pic: eui.Image) {
        pic.x = x;
        pic.y = y;
        pic.source = "light1_png";
        if (!pic.parent) {
            this.addChild(pic);
        }
        if (!pic.visible) {
            pic.visible = true;
        }
        if (this.linArr.indexOf(pic) == -1) {
            this.linArr.push(pic);
        }
    }



    /**暂存提示消息 */
    private sour: string = "";
    /**处理提示消息先后顺序 */
    public saveSour(str: string) {

        // if ((this.sour == "word6")
        //     || (this.sour == "word7")
        // ) {
        //     this.sour = str;

        // } else {

        // }

        // switch(str){
        //     case "word6":
        //     break;
        // }


        this.sour = str;

    }

    /**展示提示消息 */
    public setSour(str: string) {
        this.promptWord.setSour(str);
    }


    /**判断回合交换信息 */
    private JudgeRound() {

        // this.isBaiqiu;
        let typenum = 3;
        let ismy = false;



        //正常击球花色确认
        if (this.myColor == -1) {
            if (!this.seeAboutSurplus(this.getnowshootcolor(), this.ballArr)) {

                if (this.seeAboutBallColor(this.removeBallArr[0]) == 0) {//实心
                    if (!webNetworkMananger.getInstance().isMoving) {
                        this.homeServer.confirmColor(0);
                    } else {
                        webNetworkMananger.getInstance().confirmColor(GameData.myUserData.userId, GameData.rivalUserData.userId);
                    }
                } else {//花心
                    if (!webNetworkMananger.getInstance().isMoving) {
                        this.homeServer.confirmColor(1);
                    } else {
                        webNetworkMananger.getInstance().confirmColor(GameData.rivalUserData.userId, GameData.myUserData.userId);
                    }
                }
            }
        }



        //正常击球交换球权
        if (this.firstCollision == this.getnowshootcolor()) {
            if (this.removeBallArr.length > 0) {
                if (this.seeAboutBallColor(this.removeBallArr[0]) == this.getnowshootcolor()) {
                    typenum = 3;
                }
                else {
                    typenum = 2;
                }
                if (this.getnowshootcolor() == -1) {
                    typenum == 3;
                }
            } else {//没进球

            }
            ismy = false;
        } else {//击球犯规
            typenum = 2;
            ismy = false;
        }




        //白球进洞
        if (this.baiBallIntoNow) {
            if (this.isFirstLeg) {
                typenum = 1;
            } else {
                typenum = 2
            }
        }


        //黑球进洞
        if (this.blackBallIntoNow) {


            if (this.isFirstLeg) {
                //第一回合黑球复位
            } else {
                //判定胜负
                if (this.seeAboutSurplus(this.getnowshootcolor(), this.ballArr)) {

                } else {

                }
            }

        }



        let GameMode;
        let NextOperatePlayer;
        if (webNetworkMananger.getInstance().isMoving) {
            GameMode = webNetworkMananger.getInstance().SendShootEndMeesage;
            if (ismy) {
                NextOperatePlayer = GameData.myAccount;
            } else {
                NextOperatePlayer = GameData.rivalUserData;
            }
        } else {
            GameMode = this.homeServer.exchangeBall;
            if (ismy) {
                NextOperatePlayer = true;
            } else {
                NextOperatePlayer = false;
            }
        }
        // GameMode(typenum, NextOperatePlayer);
        console.log("GameMode   ", GameMode, "typennum   ", typenum, "NextOperatePlayer  ", NextOperatePlayer);


    }


    private seeAboutHaveMycolor(rba: number[]): boolean {
        for (var y = 0; y < rba.length; y++) {
            if (this.seeAboutIsMyColor(this.myColor, rba[y])) {
                return true;
            }
        }
        return false;
    }


    /**将杆的层级调至最高 */
    private setGanOver(GameObject: egret.DisplayObject) {

        var ganIndex = this.getChildIndex(GameObject);
        this.setChildIndex(this.ganImg, ganIndex + 1)
        this.setChildIndex(this.slipgroup, ganIndex + 2);
        this.setChildIndex(this.ld, ganIndex + 3);
        this.setChildIndex(this.menu, this.numChildren - 1);
    }


    /**清空连进计数器 */
    public clearnowCombox() {
        this.nowCombox = 0;
    }

    /**根据球ballArr同步进球显示 */
    public BallArrToShow() {
        var ballsource = ["1s", "2s", "3s", "4s", "5s", "6s", "7s", "8s", "9s", "10s", "11s", "12s", "13s", "14s", "15s", "8s"];
        let ba = this.ballArr;
        let bi = this.ballImgArr;
        this.ball1.name = "ball1";
        this.ball2.name = "ball2";
        this.ball3.name = "ball3";
        this.ball4.name = "ball4";
        this.ball5.name = "ball5";
        this.ball6.name = "ball6";
        this.ball7.name = "ball7";
        this.ball8.name = "ball8";
        this.ball9.name = "ball9";
        this.ball10.name = "ball0";
        this.ball11.name = "ball11";
        this.ball12.name = "ball12";
        this.ball13.name = "ball13";
        this.ball14.name = "ball14";
        this.ball15.name = "ball15";
        this.ball16.name = "ball16";

        // console.log(this.ballArr, this.ballImgArr)
        if ((ba.length == 0) || (bi.length == 0)) { return; }

        /**便利球的显示数组 */
        for (var i = 0; i < this.ballImgArr.length - 1; i++) {

            //ballArr    0 1 2 3 4 5 6 7 8     	9 10 11 12 13 14 15 
            //ballImgArr   1 2 3 4 5 6 7 8 		9 10 11 12 13 14 15 8

            if (ba[i + 1].isJindong == -1) {
                bi[i].source = ballsource[i];
            } else {
                bi[i].source = "dark";
            }

        }
        if (this.myColor != -1) {
            this.SMColor(this.myColor);
        }
        this.seeAboutSurplus(1, this.ballArr);
        this.seeAboutSurplus(0, this.ballArr);
    }

    /**停止球的滚动 */
    public StopAllBall() {

        this.removeEventListener(egret.Event.ENTER_FRAME, this.enterFrame, this);
        for (var i = 0; i < this.ballArr.length; i++) {

            var b = this.ballArr[i];
            if (b == undefined) { continue; }
            if (b.isJindong == -2) { continue; }
            b.moc = 0.9997;
            b.degree = 0;
            b.isJindong = -1;
            b.vx = 0;
            b.vy = 0;
            b.moc = 0.9997;
        }
        refreshUI();

    }

}

